GetFiles文件数量有限 [英] GetFiles Limited number of files

查看:98
本文介绍了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)

推荐答案

,除非您自己编写代码.当然,您可以创建一个进行调用的线程,然后让该应用继续其业务.



编辑您的回复==============

我有点想用户正在等待结果,但是如果使用线程,至少用户可以取消操作.

我在Google上找到此Codeproject文章.

更快的目录枚举器 [
Not unless you write the code yourself. Of course, you could create a thread that makes the call, and let the app go on about its business.



EDIT for your response ==============

I kinda figured that the user is waiting for the results, but by using a thread, at least the user can cancel the operation if he wants to...

I found this Codeproject article with google.

A Faster Directory Enumerator[^]


好问题:我会投票5.

您可能需要P/Invoke才能使用WIN32.

Good question: I''ll vote 5.

You may need P/Invoke to use WIN32.

// 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.


为什么不使用DirectoryInfo.EnumerateFiles?
why not use DirectoryInfo.EnumerateFiles ?


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆