Need Help with a Batch File

malindar

Distinguished
May 11, 2011
33
0
18,530
Hi guys

I need to orginize a folder full of scanned document for like 2 years now, i need help writing a batch file to sort the file in to folders according to the Year and month they are created.

i Googled around found some tools, but there is no way to automate this every month via the task scheduler.

Please help me guys Thanks a Load in advance
 
Solution
This sort of thing is really easy to do in PowerShell if you know how to use it:

$FromFolder = "D:\Photos"
$ToFolder = "D:\SortedPhotos"

get-childitem $FromFolder -recurse -include *.jpg |
foreach-object {
$FolderName = "$ToFolder\{0}-{1:00}" -f $_.LastWriteTime.Year, $_.LastWriteTime.Month
if ( -not (test-path $FolderName) ) { mkdir $FolderName | out-null }
$_.MoveTo( $FolderName + "\" + $_.Name )
}

dmroeder

Distinguished
Jan 15, 2005
1,366
23
20,765
So you want it to check the year and month of all the files in a directory, create new directories with a name that is month and year, then put the files in the appropriate directory. Does that sound right?

What file extension are they? Will there be files of any other extension in the directory?
 

dmroeder

Distinguished
Jan 15, 2005
1,366
23
20,765
What the guy wanted to do with a batch file was a bit complicated for me, however, it was really easy to do with VB. I'd be curious to see what you come up with using a batch.

In my VB program an example of folder that I created would be "2011 Jun", then I just dump any file that was created that in that month and year into it. I had a bunch of random .jpg's handy so I toyed around with those.
 

ricno

Distinguished
Apr 5, 2010
582
0
19,010


I will throw something together using CMD and then we can compare it. :)


 
This sort of thing is really easy to do in PowerShell if you know how to use it:

$FromFolder = "D:\Photos"
$ToFolder = "D:\SortedPhotos"

get-childitem $FromFolder -recurse -include *.jpg |
foreach-object {
$FolderName = "$ToFolder\{0}-{1:00}" -f $_.LastWriteTime.Year, $_.LastWriteTime.Month
if ( -not (test-path $FolderName) ) { mkdir $FolderName | out-null }
$_.MoveTo( $FolderName + "\" + $_.Name )
}
 
Solution

malindar

Distinguished
May 11, 2011
33
0
18,530
Dman THG dosent send a notification when there is a reply totaly missed to check the thread..

i managed to find a VB script and modify it..Thank you so much for your input guys...so sorry i didnt get to reply