Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication5
- {
- class Program
- {
- static void SetAllFilesAsReadOnly(string rootPath)
- {
- Console.ForegroundColor = ConsoleColor.White;
- int changed = 0;
- List<string> files = new List<string>();
- foreach (string file in System.IO.Directory.EnumerateFiles(rootPath, "*.*", System.IO.SearchOption.AllDirectories))
- {
- System.IO.FileAttributes attr = System.IO.File.GetAttributes(file);
- if ((attr & System.IO.FileAttributes.ReadOnly) == 0)
- {
- attr = attr | System.IO.FileAttributes.ReadOnly;
- System.IO.File.SetAttributes(file, attr);
- changed++;
- files.Add(file);
- }
- }
- if (changed > 0)
- {
- Console.SetCursorPosition(2, 4);
- Console.WriteLine("These are the files changed:");
- Console.ForegroundColor = ConsoleColor.Green;
- foreach (string file in files)
- {
- Console.WriteLine(" " + file);
- }
- Console.ForegroundColor = ConsoleColor.White;
- Console.WriteLine("");
- Console.WriteLine(" Write-protection was set on {0} files.", changed);
- }
- else
- {
- Console.SetCursorPosition(2, 2);
- Console.Write("Write-protection was not changed on any files.", changed);
- }
- Console.ForegroundColor = ConsoleColor.Black;
- Console.ReadKey();
- }
- static void Main(string[] args)
- {
- Console.SetCursorPosition(2, 2);
- Console.Write("Please enter the path of the directy you wish to check: ");
- Console.ForegroundColor = ConsoleColor.Green;
- string pathstring = Console.ReadLine();
- Console.Clear();
- SetAllFilesAsReadOnly(pathstring);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement