File Filter


  • Hello I try to make a program that takes files from one foder and copy them to another folder with some subfolders

    I have a promblem


    string fpath = null; //The Source Folder that user select
    string fpath2 = null; //The destination folder that user select
    private void button3_Click(object sender, EventArgs e)
                string[] files = Directory.GetFiles(fpath);
    // I create third path which included by fpath2 and an extra folder
                string fpath3 = fpath2 + "/FileFilter";
             //create third path
                    foreach (string s in files)
                       //get file type
                        string FileType = Path.GetExtension(s);
                       //get name of the file
                       string fileName = Path.GetFileName(s);
                       //test the type of file
                        if (FileType == ".txt")
                           //create a subfolder with name TXT_Files inside fpath3
                            Directory.CreateDirectory(fpath3 + "/TXT_Files");
                          //Now copy file "s" to the previous directory I have made(fpath3 + "/TXT_Files") + the filename
                            File.Copy(s, fpath3 + "/TXT_Files" + fileName, true);
                        //The same here
                        if (FileType == ".pdf")
                            Directory.CreateDirectory(fpath3 + "/PDF_Files");
                            File.Copy(s, fpath3 + "/PDF_Files" + fileName, true);

    The promblem is that the ex. txtfile have name "wasd" and the program move the file to fpath3, but no to the subfolder TXT_Files and name the file "TXT_Fileswasd.txt" why???

    Saturday, April 8, 2017 1:12 PM


All replies