• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 588
  • Last Modified:

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.
0
fireguy1125
Asked:
fireguy1125
  • 4
  • 3
  • 2
  • +2
2 Solutions
 
fireguy1125Author Commented:
Attaching screenshot of folders/files
jpgs.JPG
0
 
Gary CaseRetiredCommented:
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
0
 
Nick67Commented:
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
prashanthdCommented:
Try the following

regards
Prashanth
folder_path="G:\Recover2\" 'ensure path ends with "\"
move_folder_path="G:\Recover3\" 'ensure path ends with "\"

On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objfso.GetFolder(folder_path)

For Each objFile in objFolder.Files
	If InStr(LCase(objfile),".jpg")>0 Then
    	Wscript.Echo objFile.Name
    	strday=day(objfile.DateLastModified)
    	strmonth=Month(objfile.DateLastModified)
    	stryear=Year(objfile.DateLastModified)
    	If Len(strday)=1 Then
    		strday="0" & strday
    	End If
    	If Len(strmonth)=1 Then
    		strmonth="0" & strmonth
    	End If
    	cfol=move_folder_path&stryear&"_"&strmonth&"_"&strday&"\"
    	If Not objfso.FolderExists(cfol) Then
    		objfso.CreateFolder(cfol)
    	End If
    	objFSO.MoveFile objfile.Path , cfol
    End If	
Next

Open in new window

0
 
TheGorbyCommented:
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.
0
 
prashanthdCommented:
If you are running from command prompt, using cscript filename.vbs then removing line 10 is not required, otherwise you can remove.

Thanks @TheGorby
0
 
TheGorbyCommented:
I learn something new everyday! Thanks :)
0
 
fireguy1125Author Commented:
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:\
0
 
TheGorbyCommented:
I don't mean to step on Prashanth's toes but the path in line 1 is slightly wrong, needs to be changed as follows:
folder_path="G:\Recover2\JPG\"

Open in new window


You'll definitely want to run it like "cscript G:\movebydate.vbs" as he suggested.
0
 
fireguy1125Author Commented:
Nick67, attached file.
dir.txt
0
 
fireguy1125Author Commented:
Thanks both Prashanth and TheGorby, when line 1 was corrected as per TheGorby, it ran fine.  thank you both so much!
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 4
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now