我想通过再入侵在名录结构内找到所有前线文件。 问题在于目录中使用的搜索模式。 仅允许一次性延期。
没有人知道如何这样做,或者我不得不多次通过名录来寻求具体延长? 或者,你只能 gr取每一个档案,然后通过这份清单寻找具体延期。 这两种方法都没有效率。
增 编
我想通过再入侵在名录结构内找到所有前线文件。 问题在于目录中使用的搜索模式。 仅允许一次性延期。
没有人知道如何这样做,或者我不得不多次通过名录来寻求具体延长? 或者,你只能 gr取每一个档案,然后通过这份清单寻找具体延期。 这两种方法都没有效率。
增 编
在“网络”中,每个版本都有搜索。 网上和搜索处。 全局
在“网络4”中,你可以高效
var regex = new Regex(@"d+", RegexOptions.Compiled);
var files = new DirectoryInfo(topdir)
.EnumerateFiles("*.*", SearchOption.AllDirectories)
.Where(fi => regex.IsMatch(fi.Name));
(这一名数字的档案过滤器)
为此,撰写一份复读的计算方法(收益回报),以归还所有档案,并过滤结果,如:
IEnumerable<FileInfo> Recurse(string topdir)
{
// for each GetFiles() array element
// if is_not_dir yield return
// else Recurse(subdir)
}
var filtered = Recurse.Where(fi => regex.IsMatch(fi.Name));
HTH
修改你的休养假,并列出各种模式。 页: 1
static private void walk(String name)
{
try
{
foreach (String pattern in Patterns)
{
foreach (String f in Directory.GetFiles(name, pattern))
{
Console.WriteLine(f);
iii
iii
foreach (String d in Directory.GetDirectories(name))
{
walk(d);
iii
iii
catch
{
iii
iii
如果你只想获得所有前线文件,则使用“.xl”。
Otherwise I would suggest to call Directory.GetFiles
without pattern and filter the matching extensions by hand.
To loop through directory and sub directories, No Matter how much sub folder or files are, you can get the files into an array. You can specify the type file, Jpeg, Excel, Msword what ever you want in the extension section.
string [] Excel_Files;
String path = "what ever is your path";
Files= Directory.GetFiles(Path, "*.XL", SearchOption.AllDirectories).Select(x => Path.GetFileName(x)).ToArray();
or To specify Multiple search option for different file extensions you can do like this:
public string[] getFiles(string SourceFolder, string Filter,
System.IO.SearchOption searchOption)
{
ArrayList alFiles = new ArrayList();
string[] MultipleFilters = Filter.Split( | );
foreach (string FileFilter in MultipleFilters)
{
alFiles.AddRange(Directory.GetFiles(SourceFolder, FileFilter, searchOption));
}
return (string[])alFiles.ToArray(typeof(string));
}
public void button_click()
{
string[] sFiles = getFiles(Server.MapPath("~/"),
"*.gif|*.jpg|*.png|*.bmp|*.XL|*.PNG",
SearchOption.AllDirectories);
foreach (string FileName in sFiles)
{
Response.Write(FileName + "<br />");
}
}
我认为,第二种选择更为有效。 每一档案中都有以下格式:xl,然后缩小清单,寻找特定终点。
类似:
foreach (String f in Directory.GetFiles(path, "*.xl*", SearchOption.AllDirectories))
{
if (HasSomeExcelExtension(f))
files .Add(f);
}
您可以采用终端系统,对每一展期进行“f”检查,或利用“途径”提取展期。 扩大方法,并把它放在包含所期望的延伸的斜体内。
just my $.02 hth
What is the use of default keyword in C#? Is it introduced in C# 3.0 ?
I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...
I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...
I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...
I have two EF entities. One has a property called HouseNumber. The other has two properties, one called StartHouseNumber and one called EndHouseNumber. I want to create a many to many association ...
How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...
Since I cannot order my dictionary, what is the best way of going about taking key value pairs and also maintaing an index?
Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...