如何处理重复的压缩文件

how to handle duplicate zipped files

我手上有一个有趣的熟食店。我创建了一个程序,它采用 1-∞ 压缩文件,其中还包含 X 数量的单个文件。出于某种原因,不同文件夹中的文件有时会获得相同的文件名。这是我到目前为止的代码...

这段代码的作用是在实例化的对象之后,另一个对象调用这个名为unzip()的函数。 failsafe.check_directory() 只是确保临时文件夹是空的。第一个 try catch 用于我还不知道的任何内容,但第二个 try catch 用于捕获重复的重复文件,因此当它实际发生时......程序不会中断。所以我要问的问题是,处理此异常的最佳方法是什么,而不仅仅是将重复项踢到一边,或者换句话说,是否要在文件迟到之前重命名该文件。

        public bool unzip()
    {
        int bad_file = 0;
        failsafe.check_directory();
        string dupes = "dupe files\r\n";
       try
         {
            for (int i = 0; i < zippedfolders.Length; i++)
            {
                try
                {
                    bad_file = i;
                    ZipFile.ExtractToDirectory(zippedfolders[i], temppath);
                }
                catch
                {
                    dupes += zippedfolders[bad_file]+"\r\n";
                   continue;
                }

            }
            File.WriteAllText(@"C:\MDSSCRUBBER\BUGGED_FILE.txt", dupes);
            files = Directory.GetFiles(temppath);
            return true;
        }
        catch
        {
            return false;
        }

    }

我就是这样处理的...出于某种奇怪的原因,目录 class 没有在桌面上创建文件夹。

 private void fix_desktop()
    {
        string pathington = Environment.SpecialFolder.Desktop + @"\MrEncrypto\";
        bool check = !Directory.Exists(pathington);
        string finaloutput = Environment.SpecialFolder.Desktop + @"\MrEncrypto\";
        if (!check)
        {
            Directory.CreateDirectory(pathington);
        }
        else
        {
            foreach (string file in Directory.GetFiles(Environment.SpecialFolder.Desktop + @"\MrEncrypto"))
            {
                File.Delete(file);
            }
        }

        foreach (string file in files)
        {
            try
            {
                FileStream fsInput = new FileStream(file, FileMode.Open, FileAccess.Read);
                FileStream fsencrypt = new FileStream(finaloutput + Path.GetFileName(file), FileMode.Create, FileAccess.Write);
                /** DESCryptoServiceProvider DES = new DESCryptoServiceProvider();
                 DES.Key = ASCIIEncoding.ASCII.GetBytes(key);
                 DES.IV = ASCIIEncoding.ASCII.GetBytes(IV);**/
                AesCryptoServiceProvider DES = new AesCryptoServiceProvider();
                DES.BlockSize = 128;
                DES.KeySize = 256;
                DES.IV = ASCIIEncoding.ASCII.GetBytes(IV);
                DES.Key = ASCIIEncoding.ASCII.GetBytes(key);
                DES.Padding = PaddingMode.PKCS7;
                DES.Mode = CipherMode.CBC;
                ICryptoTransform desencrypt = DES.CreateEncryptor();
                CryptoStream ocstream = new CryptoStream(fsencrypt, desencrypt, CryptoStreamMode.Write);
                //reading time
                byte[] filetobyte = new byte[fsInput.Length - 1];
                fsInput.Read(filetobyte, 0, filetobyte.Length);
                ocstream.Write(filetobyte, 0, filetobyte.Length);
                fsInput.Close();
                ocstream.Close();
                fsencrypt.Close();
            }
            catch
            {
                continue;
            }
        }//foreach
        SystemSounds.Beep.Play();
        Encrypto.Enabled = false;
    }//function