本文介绍了GetFiles文件数量有限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web服务,该服务读取包含40 000个文件的目录的内容,因此每次服务调用GetFiles都需要一定的时间.

我的问题是是否可以请求多个文件,例如GetFiles(Path,StartIndex,Count)

I have a web service which reads the content of a directory which contains 40 000 files so each time the service calls GetFiles it takes ages.

My question is it possible to request a number of files, for something like GetFiles(Path, StartIndex, Count)

推荐答案


// The CharSet must match the CharSet of the corresponding PInvoke signature
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
struct WIN32_FIND_DATA
{
    public uint dwFileAttributes;
    public System.Runtime.InteropServices.ComTypes.FILETIME
        ftCreationTime;
    public System.Runtime.InteropServices.ComTypes.FILETIME
        ftLastAccessTime;
    public System.Runtime.InteropServices.ComTypes.FILETIME
        ftLastWriteTime;
    public uint nFileSizeHigh;
    public uint nFileSizeLow;
    public uint dwReserved0;
    public uint dwReserved1;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst=260)]
    public string cFileName;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst=14)]
    public string cAlternateFileName;
}

[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
static extern IntPtr FindFirstFile(string lpFileName,
    out WIN32_FIND_DATA lpFindFileData);

[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
static extern bool FindNextFile(IntPtr hFindFile,
       out WIN32_FIND_DATA lpFindFileData);
}



你看?使用FindFirstFile只能找到一个文件,然后使用FindFirstFile返回的指针使用FindNextFile.
不幸的是,我没有看到如何实现StartIndex.但是,您可以想到此方法与重命名架构的某种组合.



You see? Using FindFirstFile you find only one file, then you work with FindNextFile using a pointer returned by FindFirstFile.
Unfortunately, I don''t see the how to implement StartIndex. However, you can think of some combination of this method with some renaming schema.



这篇关于GetFiles文件数量有限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 13:44