Last post Jan 17, 2018 12:11 PM by aspfun
Jan 12, 2018 07:54 PM|aspfun|LINK
There are three folders: A, B and C
There are 5 files in A.
How to code to move first file (No matter how to sort) to B and move 4 files to C?
Jan 12, 2018 09:19 PM|ryanbesko|LINK
This sounds like a homework assignment. Google moving files and foreach loops.
Jan 15, 2018 11:37 AM|Eric Du|LINK
According to your description and needs, please check the following sample code:
protected void Button1_Click(object sender, EventArgs e)
DirectoryInfo sourceinfo = new DirectoryInfo(@"C:\FirstDirectory");
DirectoryInfo target = new DirectoryInfo(@"C:\SecondDirectory");
DirectoryInfo othertarget = new DirectoryInfo(@"C:\ThirdDirectory");
for (int i = 0; i < sourceinfo.GetFiles().Length; i++)
if (i == 0)
sourceinfo.GetFiles()[i].CopyTo(Path.Combine(target.ToString(), sourceinfo.GetFiles()[i].Name), true);
sourceinfo.GetFiles()[i].CopyTo(Path.Combine(othertarget.ToString(), sourceinfo.GetFiles()[i].Name), true);
Jan 16, 2018 01:44 PM|aspfun|LINK
This way will only move first file which I want.
Jan 17, 2018 07:16 AM|Eric Du|LINK
According to your description, you say this way only move the first file, if you test my code in your side, i test it in my side, I put five files in the folder "FirstDirectory", then execute my code, it move the first file to "SecondDirectory", then the
rest of them be moved to the "ThridDirectory". Here is result screenshot:
I hope you could test my code in your side.
Jan 17, 2018 12:11 PM|aspfun|LINK
Sorry, I did not describe clearly.
Your code is just what I want.
Moving first item to one folder and moving the rest of items to another folder.
Thank you again for your help.