We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


Need script to batch move files from folders

Medium Priority
Last Modified: 2012-08-13
I recently ran a file recovery program from a damaged disk, however it restored all my files into 368 seperate folders, with no real logistics behind it.  I need a script or batch file that will move files by extension into seperate folders.

All files are located in folders called G:\Recover\recup_dir.1 through G:\Recover\recup_dir.368

Within each of the recup_dir.1 , .2 , .3 etc... folders are various different file types ranging from exe to jpg, etc.

I would like the script/batch file to run through each of these recup_dir.### folders and MOVE files by extension into a new folder created under G:\Recover\JPG and G:\Recover\DOC etc.

If also possible, I would like to specify it move files with *.jpg extension only larger than 1MB into the G:\Recover\JPG folder.

Thank you in advance. Be advised I have limited knowledge in creating/modifying scripts, so I basically need the code and just so I can execute it.
Watch Question

Is there a specific reason you want this in script format?  Windows explorer search can easily do this for you, to include file size exclusion.  When you get the results just drag them into the folder you want.


Wow, it slipped my mind.  Well in any case I tried on the mp3s, which were only 30 or so of them.  But when I try it on the DOC files, I run the search results, ends up with about 1,500 of them, then i select all, hit cut, then when i go to paste in the DOC folder, an Error Moving File or Folder window comes up with: Cannot move file: cannot read from the source file or disk
try this code, I just wrote it in Notepad so hopefully I didn't have any typos.

I recommend you backup those files somewhere before you run the script
On Error Resume Next
Dim SourceFolder, DestinationFolder, FileExt As String
SourceFolder = "G:\Recover\recup_dir."
DestinationFolder = "G:\Recover\"

Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")
For i = 1 To 368
    For Each fil In fso.getfolder(SourceFolder & i).Files
        FileExt = Right(fil, InStrRev(fil, "."))
        If fso.folderexists(DestinationFolder & fil) = False Then
            fso.createfolder (DestinationFolder & fil)
        End If
        fso.movefile fil, DestinationFolder & fil & "\"
    Next fil

Open in new window

Some of the recovered file are probably corrupt then, in that case my script will likley give you the same result
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview


Ok, so to better complicate things, and looking at the search results more carefully there are several files of the same name located within zip files and other folders.  see attached image.  Any hope?


May something in the script that if it finds the same filename to rename additional files with the same name by say adding a _1 _2 _3, etc to them? Not sure if the duplicate names contain identical data, otherwise i'd say just search and delete duplicates.


Also, I need a script that takes the 6,800 jpg files that are randomly named, to see the modified date of each of these jpg files and move them to a folder that the script will creat with the modified date as the folder name.

So I have all the pictures in G:\Recover2\JPG folder would like subfolders created with the modified date as the name and move those pictures on that date modified into each folder.  
replace this line from CitizenRon's code with the code below.
objFile.Move(strSourceFolder & strExtension)

if not objFSO.fileexists(objFile) then
      objFile.Move(strSourceFolder & strExtension)
      objFile.Move(strSourceFolder & strExtension & "\1_" & objFile.Name 
end if

Open in new window

 This will add 1_ in tbe beggining of the file name if it already exists
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Before we go into the modified date script. Check to make sure the modified date didn't get reset when you recovered the files


Ok great, got the pictures into the JPG folder.  And yes I can confirm that the modified date didn't get reset.


Thank you both MaximumIQ and CitizenRon. I have opened another question for the Modified Date script here: https://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_26990370.html
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.