silverlight - Check if file exists in folder in c# -


I'm moving files from the source folder to the destination folder. Before transferring files, I am checking that the directory is OK or not. This issue is with my second investigation, where I have to ensure that the folder is not empty before running files, but it is not giving me the correct result.

String SourceFolder = (twitterDO.Path + "\\" + msgDate.Year.ToString () + "\\" + msgDate.Month.ToString () + "\\" + msgDate.Day.ToString () + "_Temp" ).To change("\\", @"\"); String Destination = Folder = (twitterDO.Path + "\\" + msgDate.Year.ToString () + "\\" + msgDate.Month.ToString () + "\\" + msgDate.Day.ToString ()). Change ("\\", @ "\"); String pattern = "* .txt"; {Directory.Exists (sourceFolder) {if (File.Exists (pattern)} {foreach (new directoryInfo (sourceFolder) .GetFiles (pattern)} {file.MoveTo (Path.Combine (destinationFolder, file.Name)) ; }} If (Directory.GetFiles (sourceFolder). Length == 0) // before making sure that the Temp folder is empty. Directory. Delete (sourcefolder, true); // Delete the template folder after moving all the contents.}}

I know that I'm making a small mistake but I'm not sure what this is. The following is a screenshot of the result that I got in the immediate window.

There is some redundancy in your current code. Starting with If-check, here's how I will give it:

  var source Directory = new DirectoryInfo (sourceFolder); // Remember this, if (sourceDirectory.Exists) find the files in the {// directory, if no one is found, then empty range will be (source.directory.GetFiles (pattern) in the source file {file.MoveTo (Path.Combine) (DestinationFolder, file.Name)); } // Check the directory again for any remaining file (SourceDirectory.GetFiles (pattern). Length == 0) // Before ensuring that the Temp folder is empty, sourceDirectory.Delete (); // Delete the template folder after moving all the contents}   

As a small display improvement, you can use the sourceDirectory.GetFiles () to sourceDirectory .EnumerateFiles () with - loop This will allow them to start walking because they find the method, not after all they are found.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -