Esempio n. 1
0
        /// <summary>
        /// 选择壁纸保存路径
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void savePathBox_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            string nowSavePath = this.savePathBox.Text;

            FolderBrowserDialog dialog = new FolderBrowserDialog();

            dialog.Description = "请选择壁纸存放路径";
            object isOk = dialog.ShowDialog();

            if (isOk.ToString().Equals("OK"))
            {
                string newPath = dialog.SelectedPath;
                this.savePathBox.Text = newPath;

                // 目录改变,移动已保存的壁纸
                if (!nowSavePath.Equals("") && !nowSavePath.Equals(newPath))
                {
                    DirectoryInfo TheFolder = new DirectoryInfo(nowSavePath);
                    foreach (FileInfo NextFile in TheFolder.GetFiles())
                    {
                        NextFile.MoveTo(newPath + NextFile.FullName);
                    }

                    Directory.Delete(nowSavePath, true);
                }

                this.setConfig("savePath", newPath);
            }
            // 复制聚焦壁纸
            this.copyWallpaper(true);
        }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            Random        rand      = new Random(DateTime.Now.Second);
            string        dir       = textBox2.Text;
            string        pfx       = textBox3.Text;
            string        ext       = textBox4.Text;
            DirectoryInfo TheFolder = new DirectoryInfo(dir);

            //遍历文件
            foreach (FileInfo NextFile in TheFolder.GetFiles("*" + ext))
            {
                string NewFilename = string.Format("{0}\\{1}{2}{3}", dir, pfx, rand.NextDouble().ToString().Substring(2, 10), ext);
                textBox1.Text += string.Format("Old:{0} new:{1}\r\n", NextFile.FullName, NewFilename);
                NextFile.MoveTo(NewFilename);
            }
            //this.listBox2.Items.Add(NextFile.Name);
        }
Esempio n. 3
0
        private void dealfile(DirectoryInfo theFolder)
        {
            DirectoryInfo[] dirInfo = theFolder.GetDirectories();
            foreach (FileInfo NextFile in theFolder.GetFiles())  //遍历文件
            {
                if (!IsFileType(NextFile))
                {
                    continue;
                }
                fileIndex++;
                this.label1.Text = "正在处理第 " + fileIndex + " 个文件";
                System.Windows.Forms.Application.DoEvents();
                string fileKey = getFileKey(NextFile);//via fileName and size to identidy file
                if (!fileInfo.Keys.Contains(fileKey))
                {
                    fileInfo.Add(fileKey, NextFile.FullName);
                }
                else
                {
                    string text = "文件序号" + fileIndex + ":" + NextFile.Name + ",大小:" + NextFile.Length + "字节。";
                    this.textBox1.Text += text + "是重复文件。\r\n";
                    if (Directory.Exists(dumpfilefolderName) == false)//如果不存在就创建文件夹
                    {
                        Directory.CreateDirectory(dumpfilefolderName);
                    }
                    //将重复文件剪切到指定文件夹
                    try
                    {
                        WriteFile(dumpfilefolderName + @"\movelog.txt", text + "保留原始文件" + fileInfo[fileKey] + ",来自" + NextFile.FullName + "被移出。");
                        string fileNewName = NextFile.Name.Substring(0, NextFile.Name.IndexOf(".")) + NextFile.Length + NextFile.Name.Substring(NextFile.Name.IndexOf("."), NextFile.Name.Length - NextFile.Name.IndexOf("."));
                        NextFile.MoveTo(dumpfilefolderName + @"\" + fileNewName);
                        dupfiles++;
                        savebit += NextFile.Length;
                    }
                    catch { }
                }

                // this.listBox2.Items.Add();
            }
            //递归遍历文件夹

            foreach (DirectoryInfo NextFolder in dirInfo)
            {
                dealfile(NextFolder);
            }
        }