I was able to successfully remove the readable attributes on the file using the following code snippet:
< P> Main.cs FileSystemInfo [] sqlParentFileSystemInfo = dirInfo.GetFileSystemInfos (); Forchach (var childFolderOrFile in sqlParentFileSystemInfo) {RemoveReadOnlyFlag (childFolderOrFile); } Private Static Zero RemoveReadOnlyFlag (FileSystemInfo fileSystemInfo) {fileSystemInfo.Attributes = FileAttributes.Normal; Var di = fileSystemInfo DirectoryInfo; If (di! = Null) {foreach (var dirInfo di.GetFileSystemInfos ()) RemoveReadOnlyFlag (dirInfo); }}
Unfortunately, it does not work on folders. After running the code, when I go to the folder, right click and create the property, here I am looking for:
The read only flag is still checked, though it has been removed from the files below it to fail to delete this folder. Causes the process. When I manually remove the flag and run the process again (the bat file), then it is capable of removing the file (so I know it is not a problem with the ballet file).
How do I remove this flag? You can do anything similar to the following, to clarify only the following readable (and collections, etc.): C #?
Private Zero ClearReadOnly (DirectoryInfo parentDirectory) {if (parentDirectory! = Null) {parentDirectory.Attributes = FileAttributes.Normal; Foreign currency (file infoines in parent directory .gatfile (file) {fi Properties = File attributes. Normal; } Foreach (directoryInfo di parentDirectory.GetDirectories ()) {ClearReadOnly (di); }}
So you can call it like this:
public zero main () {DirectoryInfo parentDirectoryInfo = new DirectoryInfo (@ "c: \ Test "); ClearReadOnly (parentDirectoryInfo); }
No comments:
Post a Comment