i need to sort files by date into different folders.
all files from januar must be moved from their current directory to a folder named januar and all files from february to a folder named february and so on..
the folder is not created, so the code have to create a folder from the date of the files..
Does any one of you know how to do this ?
:)
Loading
VulpesPosted Mar 5, 2013, 10:20 AM
Try this:
jesperPosted Mar 5, 2013, 9:36 AM
Its exact wat i wanted.. but the code have to create the folders on demand, is it still not clear :/ ?
VulpesPosted Mar 5, 2013, 9:22 AM
You seem to be saying that if there are any files from 2013 or older, then you need to create a folder called 2010 and then have sub-folders within that for each of the 12 months.
However, currently, all files will be dated 2013 or older and so will go into the same 2010 'top level' folder. If that's the case, you might as well define the target folder to be:
string target = @"C:\testFolder\2010";
and then use the previous code.
I'd have thought it would make more sense to have top level folders for each year and then sub-folders for the months within each of those years.
jesperPosted Mar 5, 2013, 8:18 AM
Folder structure:
year folder
month folder
files
right now i have only month folder and down..
if there is any files from 2013 og older, it needs to create a folder named 2010 and again put files from january 2010 in the folder named january for example. how do i create the upper structure.. i have tried to extract the year from the files but the output its everything else than a year :)
VulpesPosted Mar 4, 2013, 8:30 AM
jesperPosted Mar 4, 2013, 7:51 AM
VulpesPosted Mar 4, 2013, 7:26 AM
The way you couched the original question led manuprasad and myself to conclude that you wanted to group them by the month of creation?
jesperPosted Mar 4, 2013, 6:46 AM
string source = @"C:\testFolder"; //Folder where all files are stored
string target = @"C:\";
foreach (var file in Directory.EnumerateFiles(source))
{
var dest = Path.Combine(target + DateTime.Now.ToString("MMMM"),
Path.GetFileName(file));
File.Move(file, dest);
}
is it bad programming ?
my directories are created before this code is executed.
VulpesPosted Mar 4, 2013, 6:34 AM
The new directories are created as sub-directories of the current directory:
manuprasad kadavatPosted Mar 4, 2013, 5:58 AM
FileInfo MyFile as new FileInfo("c:\\scale.txt") ;
string Strcreation = MyFile.creationTime.ToString();