Click here to Skip to main content
15,885,925 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi All,

I am trying to get the file list based on the "pattern" of the file name but the code below does the job but its not lookin the files in sub directories. Any help how to look the file patterns in Sub Dir's also


C#
var getfiles = new fileshare.Program();
string realname = "*main*";
string Location = "SVR01";
var fileList = getFiles.GetFileList(realname, Location);
var anymatch = fileList.Any();

if (anymatch) // Or possibly `if (fileList.Any())` if anymatch isn't 
              // really used anywhere else
    baseMeta();

foreach (var file in getfiles.GetFileList(realname,Location))
    getfiles.copytolocal(file.FullName);
 switch (Location)
    {
        case "SVR01":
            directory = @"\\SVR01\Dev";
        break;

        case "SVR02":
            directory = @"\\SVR02\Dev";
        break;

        case "SVR03":
            directory = @"\\SVR03\Prod");
        break;

        default: 
            throw new ArgumentOutOfRangeException();

    }

    DirectoryInfo di = null;
    try
    {
        di = new DirectoryInfo(directory);
    }
    catch(Exception ex)
    {
        Console.WriteLine(ex.Message);
        yield break;
    }

    foreach(var fi in di.EnumerateFiles(pattern))
        yield return fi;
}
Posted
Comments
Dean Oliver 17-Mar-12 12:01pm    
please provide the code for your GetFileList() method

1 solution

Hi friends,

this code may help u...


C#
string[] folders = System.IO.Directory.GetDirectories(@"C:\My Sample Path\","*", System.IO.SearchOption.AllDirectories);



Check this site....
http://www.progtalk.com/viewarticle.aspx?articleid=77[^]
 
Share this answer
 
v2
Comments
shan1395 17-Mar-12 6:35am    
Thanks Vijay,true that will help me but am using pattern in my code do you noticed in my code ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900