C# windows search and move

I take it you are a junior. So:

Don't call your variables filepath and folder2. Rather called it sourceFolder and destinationFolder (self documenting code)
sPattern = searchPattern/filter
folder1 = sourceFiles

And then the variable you use to loop ... foreach(var file in sourceFiles)

You may think it is nitpicking but naming your variables better will avoid things like File.Exists(folder2)

Rather use Path.Combine() instead of string + string



If i was your boss I'd slap you and make you wash my car over the weekend ;)

LMAO, thanks for the much needed advice :) .. Well that's what I get for programming late at night....
I forgot who the program code is for , was explaining it like I would too a client :wtf:
 
If it exists, delete it, then copy the new one in??? Never do that. Just because file names are the same does not mean the contents are.

And use recursion, otherwise you'll always go only one directory deep to find your files. With recursion, you can traverse your entire hard drive.

Thanks Baron.... I also thought that...But when I tried it , it kept on giving me Exsist errors..:wtf:
But the better solution would too create a new folder with a new file name if the folder already exist...
 
Thanks Baron.... I also thought that...But when I tried it , it kept on giving me Exsist errors..:wtf:
But the better solution would too create a new folder with a new file name if the folder already exist...

Why didn't you use try/catch blocks to handle the exceptions? In the case of an exception where the file already exists, note this in a log file and proceed as normal. Afterwards notify the user of the failures. You can even include MD5 hashes of problematic files to determine whether the contents are the same or not.
 
LMAO, thanks for the much needed advice :) .. Well that's what I get for programming late at night....
I forgot who the program code is for , was explaining it like I would too a client :wtf:

you explain things to a client in a way that makes it look like you dont know what you are doing???
 
Top
Sign up to the MyBroadband newsletter
X