directoryinfo

Check if DirectoryInfo.FullName is special folder

大憨熊 提交于 2019-12-22 12:16:06
问题 My goal is to check, if DirectoryInfo.FullName is one of the special folders. Here is what I'm doing for this (Check directoryInfo.FullName to each special folder if they are equal): DirectoryInfo directoryInfo = new DirectoryInfo("Directory path"); if (directoryInfo.FullName == Environment.GetFolderPath(Environment.SpecialFolder.Windows) || directoryInfo.FullName == Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles ||) ... ... ) { // directoryInfo is the special folder } But

Why isn't this DirectoryInfo comparison working? [duplicate]

廉价感情. 提交于 2019-12-21 12:17:11
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How to check whether 2 DirectoryInfo objects are pointing to the same directory? var dirUserSelected = new DirectoryInfo(Path.GetDirectoryName("SOME PATH")); var dirWorkingFolder = new DirectoryInfo(Path.GetDirectoryName("SAME PATH AS ABOVE")); if (dirUserSelected == dirWorkingFolder) { //this is skipped } if (dirUserSelected.Equals(dirWorkingFolder)) { //this is skipped } Whilst debugging, I can examine the

C# Access to the path 'C:\Documents and Settings\' is denied

徘徊边缘 提交于 2019-12-18 06:56:14
问题 I'm using a simple DirectoryInfo to grab all directories on the root on the C drive. However, I'm running under administrator and i'm getting the error of path access denied, below is the code that I am running. How do I resolve the issue of path access? DirectoryInfo Dinfo = new DirectoryInfo(@"C:\"); DirectoryInfo[] directories = Dinfo.GetDirectories("*.*", SearchOption.AllDirectories); 回答1: On newer versions of Windows C:\Document and Settings is a junction point , kind of a file system

.NET - Check if directory is accessible without exception handling

眉间皱痕 提交于 2019-12-17 19:38:44
问题 I need to go through various directories on the computer (via DirectoryInfo). Some of them aren't accessible, and UnauthorizedAccessException occurs. How can I check directory access without catching the exception? 回答1: You need to use the Security namespace. See this SO answer. From the answers: FileIOPermission writePermission = new FileIOPermission(FileIOPermissionAccess.Write, filename); if(!SecurityManager.IsGranted(writePermission)) { //No permission. //Either throw an exception so this

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

DirectoryInfo.MoveTo - “Source and destination path must have identical roots. Move will not work across volumes.”

核能气质少年 提交于 2019-12-14 04:23:32
问题 I'm trying to figure out what is going on here. I have a routine that looks at all the directories in a directory and removes any non numeric values from the first part of a directory name. For some reason when it goes to do the MoveTo I'm getting the "Source and destination path must have identical roots. Move will not work across volumes." But I'm only providing the new name as the parameter. So the directory might be "007A Raby" and the new name passed into MoveTo would be "007 Raby".

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

Directory.GetDirectories , Sort by name C# [duplicate]

ε祈祈猫儿з 提交于 2019-12-13 00:36:48
问题 This question already has answers here : How would I sort a list of files by name to match how Windows Explorer displays them? (3 answers) C# How do I use Directory.GetFiles() to get files that have the same order as in Windows explorer? (7 answers) Closed 5 years ago . This one sounds duplicate, but all the solutions given is not satisfying one of the requirement that is sorting by name. for instance J A1 J A2 J A3 J A10 J A11 The method returns J A1,J A10, J A11, J A2, J A3. But this is not

Renaming a directory locks renamed dir the second time I want to rename

柔情痞子 提交于 2019-12-12 19:52:10
问题 I'm having problems with renaming a directory multiple times, it seems to lock the file. // e comes from a objectListView item DirectoryInfo di = (DirectoryInfo)e.RowObject; DirectoryInfo parent = Directory.GetParent(di.FullName); String newPath = Path.Combine(parent.FullName, e.NewValue.ToString()); // rename to some temp name, to help change lower and uppercast names di.MoveTo(newPath + "__renameTemp__"); di.MoveTo(newPath); // Trying to cleanup to prevent directory locking, doesn't work...