Link to home
Start Free TrialLog in
Avatar of fireguy1125
fireguy1125

asked on

Script to Move Files by Date Modified Into Folders by Date

I recently ran a recovery program on a failed hard drive that was able to recover most of my files.  Unforunately it didn't maintain the file oranizational structure and names, but miraculously maintained the date modified attribute.  I have over 6,800 JPGs in a folder, that I need a script to:

-read the date modified (excluding the time) of each of these JPGs
-create a folder for each JPG that has a date
-move the JPGs from the main folder (G:\Recover2\JPG) to the (G:\Recover3) folder into folder names that are created by the date modified attribute of these files.

Attached picture as example of files, so I have a group of JPGs that were taken on 7/24/2008, 8/2/2008, 9/19/2008, etc, I would like the script to create a folder 2008_07_24 (or something similar) and move the group of pictures that were taken on that date into the folder, essentially deletting them from the original location.

Have limited scripting knowledge, but know enough to put in notepad and rename to vbs or bat and execute.  Thanks.
Avatar of fireguy1125
fireguy1125

ASKER

Attaching screenshot of folders/files
jpgs.JPG
Avatar of Gary Case
Check out the very powerful XXCopy, which has a very extensive set of file filters to control copies.

For example, to copy all files with a date of 7/24/2008 to a folder named 24 July 08 you'd use this command:

XXCopy  G:\Recover2\JPG  G:\Recover3\24Jul08  /Do:2008-7-24

I don't offhand know if it will automatically create the destination folders, but unless you have an inordinate number of different dates it should be fairly easy to create the folders yourself & then do the copies.

XXCopy is freely available here:  http://www.xxcopy.com/xcpydnld.htm  (The freeware version is all you need)
... with an extensive manual available online:  http://www.xxcopy.com/xcpytbul.htm
Can you open a command window, navigate to g:\recover2\jpg and run the following

dir /o/p >dir.txt

That will create a file, dir.txt

Post it, and I'll build you a batch file to organize the files
Excel will see the file as a CSV.
From there it's not hard to do the rest
ie make directories and move each file
ASKER CERTIFIED SOLUTION
Avatar of prashanthd
prashanthd
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You might want to remove line 10 from Prashanth's script or you'll have to click OK on a message box that pops up for every single file. Otherwise that looks great.
If you are running from command prompt, using cscript filename.vbs then removing line 10 is not required, otherwise you can remove.

Thanks @TheGorby
I learn something new everyday! Thanks :)
I copied the code and saved into root of G:\ as movebydate.vbs, when I execute by double clicking nothing happens, don't see any movement of files between folders.  I also tried running the G:\cscript movebydate.vbs and very quickly displayed the following:

C:\cscript g:\movebydate.vbs
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.


C:\
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Nick67, attached file.
dir.txt
Thanks both Prashanth and TheGorby, when line 1 was corrected as per TheGorby, it ran fine.  thank you both so much!