Note that there are some explanatory texts on larger screens.

plurals
  1. POnot accessing my folder or directory
    primarykey
    data
    text
    <p>this program is supposed to show the path of a directory and the directory if its exists then it should also show the files inside with the following extensions (i.e .doc, .pdf, .jpg, .jpeg) i created a folder called max in the bin directory the code is running but its telling me that the directory does not exist this is my code below</p> <pre><code>namespace sharp_lab_2 { interface IFileOperation { //should handle the file bool Accept(string fileName); //handler function file void Process(string fileName); } class FileProcByExt : IFileOperation { string extName; string folderName; public FileProcByExt(string ext = "") { extName = ext; if (extName == "") folderName = "MAXee"; else folderName = extName.ToUpper(); } public bool Accept(string fileName) { bool res = false; if (extName == "" ) res = true; // all if (Path.GetExtension(fileName) == "." + extName) res = true; // has extension return res; } public void Process(string fileName) { Directory.CreateDirectory(Path.Combine(Path.GetDirectoryName(fileName), folderName)); File.Move(fileName, Path.Combine(Path.GetDirectoryName(fileName), folderName, Path.GetFileName(fileName))); } } class FileProcNameAfter10 : IFileOperation { static int cnt; public bool Accept(string fileName) { return Path.GetFileNameWithoutExtension(fileName).Length &gt; 10; } public void Process(string fileName) { File.Copy(fileName, Path.Combine(Path.GetDirectoryName(fileName), "longname_" + cnt + Path.GetExtension(fileName))); cnt++; } } class FileProcEnc: IFileOperation { public bool Accept(string fileName) { FileInfo fi = new FileInfo(fileName); return fi.Length &lt; 1024; } public void Process(string fileName) { File.Encrypt(fileName); } } class Program { static void Main(string[] args) { try { string directoryPath = args[0]; string[] filesList, filesListTmp; IFileOperation[] opList = { new FileProcNameAfter10(), new FileProcEnc(), new FileProcByExt("jpeg"), new FileProcByExt("jpg"), new FileProcByExt("doc"), new FileProcByExt("pdf"), new FileProcByExt("djvu") }; if (Directory.Exists(directoryPath)) { filesList = Directory.GetFiles(directoryPath); while (true) { Thread.Sleep(500); filesListTmp = Directory.GetFiles(directoryPath); foreach (var elem in Enumerable.Except&lt;string&gt;(filesListTmp, filesList)) { Console.WriteLine(elem); foreach (var op in opList) { if (op.Accept(elem)) op.Process(elem); } } filesList = filesListTmp; if (Console.KeyAvailable == true &amp;&amp; Console.ReadKey(true).Key == ConsoleKey.Escape) break; } } else { Console.WriteLine("There is no such directory."); Console.ReadKey(); } } catch (Exception ex) { Console.WriteLine("Error." + ex.Message); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload