getdirectories

How can I read the files in a directory in sorted order?

我的梦境 提交于 2021-02-07 06:15:14
问题 When I read a directory in Perl with opendir , readdir , and closedir , the readdir function doesn't seem to read the files in any specific order (that I can tell). I am reading a directory that has subdirectories named by epoch timestamp: 1224161460 1228324260 1229698140 I want to read in these directories in numerical order, which would put the oldest directories first. When I use readdir , the first one it reads is 1228324260, which is the middle one. I know I could put the directory

Are optional params available for the Compact Framework?

大城市里の小女人 提交于 2019-12-24 12:01:11
问题 I need to get a list of all files on a handheld device whose names fit a certain pattern, such as " ABC .XML" I adapted code from here (Hernaldo's answer), like so: public static List<string> GetXMLFiles(string fileType, string dir) { string dirName = dir; // call it like so: GetXMLFiles("ABC", "\\"); <= I think the double-whack is what I need for Windows CE device...am I right? var fileNames = new List<String>(); try { foreach (string f in Directory.GetFiles(dirName)) { if ((f.Contains

Check if directory is accessible in C#? [duplicate]

孤街浪徒 提交于 2019-12-17 12:22:23
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: .NET - Check if directory is accessible without exception handling Im making a small file explorer in Visual Studio 2010 with NET 3.5 and C#, and I have this function to check if a directory is accessible: RealPath=@"c:\System Volume Information"; public bool IsAccessible() { //get directory info DirectoryInfo realpath = new DirectoryInfo(RealPath); try { //if GetDirectories works then is accessible realpath

Check if directory is accessible in C#? [duplicate]

只愿长相守 提交于 2019-12-17 12:22:13
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: .NET - Check if directory is accessible without exception handling Im making a small file explorer in Visual Studio 2010 with NET 3.5 and C#, and I have this function to check if a directory is accessible: RealPath=@"c:\System Volume Information"; public bool IsAccessible() { //get directory info DirectoryInfo realpath = new DirectoryInfo(RealPath); try { //if GetDirectories works then is accessible realpath

C# Directory.GetFiles with mask

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-13 04:29:10
问题 In C#, I would like to get all files from a specific directory that matches the following mask: prefix is "myfile_" suffix is some numeric number file extension is xml i.e myfile_4.xml myfile_24.xml the following files should not match the mask: _myfile_6.xml myfile_6.xml_ the code should like somehing this this (maybe some linq query can help) string[] files = Directory.GetFiles(folder, "???"); Thanks 回答1: I am not good with regular expressions, but this might help - var myFiles = from file

Get directories of remote Server [duplicate]

╄→尐↘猪︶ㄣ 提交于 2019-12-13 03:08:51
问题 This question already has an answer here : Enumerating network shares (1 answer) Closed 5 years ago . I'm trying to get all directories of a remote server. For example: path: "\\Servename\folder" - it works! path: "\\Servename" - error I tried this: DirectoryInfo dir = new DirectoryInfo (@"\\SERVERNAME"); <- Error happens here //Get Directories from \\SERVERNAME DirectoryInfo[] dirInfos = dir.GetDirectories(); Error: ERROR: The UNC path should be of the form \\server\share 回答1: The reason is

UnauthorizedAccessException with getDirectories

两盒软妹~` 提交于 2019-12-12 12:23:58
问题 Hello everyone I currently got subdirectories I wanted through this call: foreach (DirectoryInfo dir in parent) { try { subDirectories = dir.GetDirectories().Where(d => d.Exists == true).ToArray(); } catch(UnauthorizedAccessException e) { Console.WriteLine(e.Message); } foreach (DirectoryInfo subdir in subDirectories) { Console.WriteLine(subdir); var temp = new List<DirectoryInfo>(); temp = subdir.GetDirectories("*", SearchOption.AllDirectories).Where(d => reg.IsMatch(d.Name)).Where((d => !d

c# Directory.GetDirectories excluding folders

蓝咒 提交于 2019-12-07 12:56:05
问题 I'm trying to iterate through a list of users folders in windows in "c:\Users" but exclude the microsoft built-in user folders, the below is the code segment I'm using to accomplish this feat but it's for some reason not working as intended. private readonly List<String> _exclusion = new List<String> { "All Users", "Default", "LocalService", "Public", "Administrator", "Default User", "NetworkService" }; public static bool FoundInArray(List<string> arr, string target) { return arr.Exists(p =>

c# Directory.GetDirectories excluding folders

本秂侑毒 提交于 2019-12-06 00:17:06
I'm trying to iterate through a list of users folders in windows in "c:\Users" but exclude the microsoft built-in user folders, the below is the code segment I'm using to accomplish this feat but it's for some reason not working as intended. private readonly List<String> _exclusion = new List<String> { "All Users", "Default", "LocalService", "Public", "Administrator", "Default User", "NetworkService" }; public static bool FoundInArray(List<string> arr, string target) { return arr.Exists(p => p.Trim() == target); } foreach (string d in Directory.GetDirectories(sDir).Where(d => !FoundInArray(

How to exclude folders when using Directory.GetDirectories

天涯浪子 提交于 2019-11-29 15:30:41
I want to return a list of all the subdirectories in the 'SomeFolder' directory excluding the 'Admin' and 'Templates' directories. I have the following folder structure (simplified): C:\inetpub\wwwroot\MyWebsite\SomeFolder\RandomString C:\inetpub\wwwroot\MyWebsite\SomeFolder\RandomString C:\inetpub\wwwroot\MyWebsite\SomeFolder\RandomString C:\inetpub\wwwroot\MyWebsite\SomeFolder\Admin C:\inetpub\wwwroot\MyWebsite\SomeFolder\Templates 'SomeFolder' can contain a varying number a 'RandomString' folders (anywhere from ~10 to ~100). Here is what I have tried: var dirs = Directory.GetDirectories