My console application (C#) is working perfectly for the filenames which don't contain any UTF-8 characters but when the filenames contain any UTF-8 character, my condition if(!File.Exists(destFilePath)) is not working as expected.
I need to delete those files which are only present in the destination but not in the source. When there some special characters in my file name, for example,
C:\A00000001\20162350775-Étienne Geoffroy Saint-Hilaire, 1772-1844 a visionary naturalist. Hervé Le Guyader.pdf
D:\A00000001\20162350775-Étienne Geoffroy Saint-Hilaire, 1772-1844 a visionary naturalist. Hervé Le Guyader.pdf
The filename in the above case should not be deleted as both source and destination have the same filename but it did. But for normal filenames, there is no issue. My code sample is as below:
public void SynchronizeSourceAndDestination(string dir)
foreach (string file in Directory.GetFiles(dir))
string destFilePath = file.Replace(BackupDirectory, LookupDirectory);
// Delete file from Backup
foreach (string directory in Directory.GetDirectories(dir))
string destinationDirectory = directory.Replace(BackupDirectory, LookupDirectory);
To make my solution workable I changed extended ASCII character by pressing É (Alt + 144), é (Alt + 130). I think it was because the file creator did some copy and paste of the characters directly.