复制到 Dropbox 文件夹中的文件与原始文件名的处理方式不同

Files Copied in the Dropbox folder are treating differently than the original file names

我正在使用 Windows 10,我有两个文件夹,即 SourceDestination。目标文件夹位于 Dropbox 中。我有两种方法 CopySourceFilesToDestinationSynchronizeSourceAndDestination。第一种方法将所有文件夹和文件从源复制到目标,而第二种方法检查特定文件名是否存在于源文件夹中,如果未在源中找到文件名,则从目标文件夹中删除特定文件。现在我有几个如下命名的文件,我不需要关心文件中的内容。

E:\Source\A0000000001162356312-Future of Utopia in History. Hayden White. Historein 7.pdf

E:\Source\T0000000142162350775-Étienne Geoffroy Saint-Hilaire, 1772-1844 a visionary naturalist. Hervé Le Guyader.pdf

E:\Source\T000000040316242657-Reveries of the solitary walker; Botanical writings; and Letter to Franquières. Jean Jacques Rousseau.pdf

E:\Source\T000000042816243154-Science of Literature- essays on an incalculable difference.Helmut Müller-Sievers.pdf

当我 运行 我的程序将文件复制到目标时,但我的 SynchronizeSourceAndDestination 方法删除了除列表中第一个不包含任何 UTF-8 字符的文件之外的所有文件。

using System;
using System.IO;

namespace DropboxDemo
{
    class Program
    {
        private static string lookupDirectory = @"E:\Source";
        private static string backupDirectory = @"C:\Users\SIMANT\Dropbox \Destination";
        static void Main(string[] args)
        {
            Console.WriteLine("Please wait while copying files.");
            CopySourceFilesToDestination(lookupDirectory);

            Console.WriteLine("Please wait while synchronizing files.");
            SynchronizeSourceAndDestination(backupDirectory);

            Console.ReadLine();
        }

        public static void SynchronizeSourceAndDestination(string dir)
        {
            foreach (string file in Directory.GetFiles(dir))
            {
                string destFilePath = file.Replace(backupDirectory, lookupDirectory);

                if (!File.Exists(destFilePath))
                {
                    // Delete file from Backup
                    File.Delete(file);
                }
            }

            foreach (string directory in Directory.GetDirectories(dir))
            {
                string destinationDirectory = directory.Replace(backupDirectory, lookupDirectory);

                if (!Directory.Exists(destinationDirectory))
                {
                    Directory.Delete(directory, true);
                    continue;
                }
                SynchronizeSourceAndDestination(directory);
            }
        }
        public static void CopySourceFilesToDestination(string dir)
        {
            foreach (string file in Directory.GetFiles(dir))
            {
                string destFilePath = file.Replace(lookupDirectory, backupDirectory);

                if (!File.Exists(destFilePath))
                {
                    File.Copy(file, destFilePath);
                }
                else
                {
                    // Override the existing file                        
                    File.Copy(file, destFilePath, true);
                }
            }

            foreach (string directory in Directory.GetDirectories(dir))
            {
                //Create directory if not present in the destination
                string destinationDirectory = directory.Replace(lookupDirectory, backupDirectory);
                if (!Directory.Exists(destinationDirectory))
                {
                    Directory.CreateDirectory(destinationDirectory);
                }
                CopySourceFilesToDestination(directory);
            }
        }
    }
}

第二次,我只是将所有文件从 Destination(在 Dropbox 中)复制到 Source 文件夹并重新运行程序,现在它没有删除文件。为什么我会出现这种行为?我认为当一个文件被复制到 Dropbox 时,它以不同的方式表示相同的文件名(我们从我眼中看到的)。你能帮我解决这个问题吗?

为了使我的解决方案可行,我通过按 É (Alt + 144)、é (Alt + 130) 更改了扩展 ASCII 字符.我想是因为文件创建者直接复制和粘贴了一些字符。