Skip to content

Commit

Permalink
πŸ“Œ Fix write permission denials πŸ“Œ
Browse files Browse the repository at this point in the history
  • Loading branch information
hahagu committed Nov 4, 2021
1 parent aa217a0 commit f16a9ae
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions Library/PathHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,30 @@ public static IEnumerable<string> GetAllDirectories(string rootDirectory, string
try
{
string[] subDir = Directory.GetDirectories(searchPath, searchPattern);
foreach (string directories in subDir) {
searchList.Push(directories);
returnList.Push(directories);
foreach (string directory in subDir) {
searchList.Push(directory);
if (IsDirectoryWritable(directory)) returnList.Push(directory);
}
}
catch { }
}

return returnList;
}


public static bool IsDirectoryWritable(string dirPath)
{
try
{
string randomFileName = Path.Combine(dirPath, Path.GetRandomFileName());
using (FileStream fs = File.Create(randomFileName, 1, FileOptions.DeleteOnClose)) { }
return true;
}
catch
{
return false;
}
}
}
}

0 comments on commit f16a9ae

Please sign in to comment.