• 0

[Batch] Batch file to move folders


Question

Hi all

I am looking for a batch file that I can run that will move folders to specific directories based upon the type of files located within each folder.

For example:

My folder structure looks like this:

\Movies\

-----\Alien\

----------\Alien.avi

-----\Iron Man\

----------\Iron Man.mkv

So basically I have a whole folder that needs to be separated into 2 groups. 1 group for HD stuff (mkv's) and 1 group fro SD stuff (avi's).

What I was looking for is a batch file that can move the second level folder (\Alien\, \Iron Man\) based upon the extension of the file within the folder (avi or mkv)

So the Alien folder would be moved to G:/SD Movies, and the Iron Man folder would be moved to F:/HD Movies.

I have googled for a while, but haven't been able to come up with anything that has worked as of yet.

Thanks for any help, and apologies if this is really simple to do, but I have absolutely no scripting experience whatsoever.

Link to comment
https://www.neowin.net/forum/topic/768970-batch-batch-file-to-move-folders/
Share on other sites

6 answers to this question

Recommended Posts

  • 0

Here is a VBS script that should do what you want. Place the script in the folder you want to move the files,

or put the full path in this part of the script. The path must have quotes around it or it will error out.

  Quote
Dim Dir :Dir  = "D:\ThisFolder"

I used the copy file then delete file in the script to avoid that the file being copy exists in the CopyTo Folders dialog.

Save As SearchMoveMovies.vbs

  Quote
 Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
'-> Makes The Folder Where The Script Located The Parent Folder
'-> Or Add A Full Path To The Folder EG: Dim Dir :Dir  = "D:\ThisFolder"
 Dim Dir :Dir = "."
'-> Where The Files Will End Up
 Dim CopyTo1, CopyTo2
'-> Avi Location
  CopyTo1 = "G:\SD Movies\"
'-> Mkv Location
  CopyTo2 = "F:\HD Movies\"
'-> Start The Search
  Recursive Fso.GetFolder(Dir)
'-> Searches Threw The Parent Folder And All Sub Folders
   Function Recursive(Folder)
   On Error Resume Next
	Dim Col :Set Col = Folder.files
	Dim File
	For Each File In Col 
	 If InStr(LCase(File.Path),".avien
	  Fso.CopyFile File.Path, CopyTo1 & File.Name, True
	  Fso.DeleteFile(File.Path)
	 End If 
	 If InStr(LCase(File.Path),".mkven
	  Fso.CopyFile File.Path, CopyTo2 & File.Name, True
	  Fso.DeleteFile(File.Path)
	 End If 
	Next
	Dim Obj
	For Each Obj In Folder.subFolders
	 Recursive Obj
	Next
   End Function
'-> End Of Script Message 
   MsgBox "Completed Movies Moves",4128,"Finished"
  • 0

Thanks Jake1eye

I tried your scipt, and it only seems to copy the files and not the folder.

Is there anyway that I could have a script look into a sub-folder for an avi file, and if it finds one, move the folder and all of the contents inside of it to a destination directory.

I did some trial and error using xcopy and xxcopy, and I was able to successfully copy an avi and mkv file, along with their folder to where I wanted them to go, but other files located in the same folder were not copied.

For example

\Movies\

-----\Alien\

----------\Alien.avi

----------\Alien.srt/idx/sub

-----\Iron Man\

----------\Iron Man.mkv

----------\Iron Man.srt/idx/sub

I was able to get the Alien folder and Alien.avi file to copy successfully, however the srt/idx/sub files wouldn't

Here is the script that I was using:

XXCOPY "F:\Downloads\Processed Downloads\Movies\*.avi" "D:\Movies\Finished SD Movies\" /S /I /C /RCY /F /PD0 /ED1 /FO"C:\Users\Kevin\Other Stuff\Usenet\Scripts\Movie Mover Logs\AVIlog.txt"

XXCOPY "F:\Downloads\Processed Downloads\Movies\*.mkv" "F:\Movies\Finished HD Movies\" /S /I /C /RCY /F /PD0 /ED1 /FO"C:\Users\Kevin\Other Stuff\Usenet\Scripts\Movie Mover Logs\MKVlog.txt"

This worked great for moving the avi and mkv file and folder, however it wouldn't move the other non avi or mkv files in the folder.

I can't specify in the script to have the srt/idx/sub files to always go to either the HD movies or SD movies, because both the avi files and mkv files come with subtitle files.

so after all of this long winded crap from me, is there anyway to just move a folder and all of its contents based on if there is an avi or mkv file inside?

  • 0

Sorry I thought you only wanted the movie file moved to the new folder. Here is a script

that will move the folder if there a Avi or Mkv file in the folder

Save As MoveMoviesFolder.vbs

  Quote
 Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
'-> Makes The Folder Where The Script Located The Parent Folder
'-> Or Add A Full Path To The Folder EG: Dim Dir :Dir =  "D:\ThisFolder"
 Dim Dir :Dir = "."
'-> Where The Files Will End Up
 Dim CopyTo1, CopyTo2
'-> Avi Location
  CopyTo1 = "D:\SD Movies\"
'-> Mkv Location
  CopyTo2 = "F:\HD Movies\"
'-> Start The Search
  Recursive Fso.GetFolder(Dir)
'-> Searches Threw The Parent Folder And All Sub Folders
   Function Recursive(Folder)
   On Error Resume Next
	Dim Col :Set Col = Folder.files
	Dim File, F1
	For Each File In Col 
	 If InStr(LCase(File.Path),".avien
	  Set F1 = Fso.GetFolder(Fso.GetParentFolderName(File.Path))
	   Fso.CopyFolder F1.Path, CopyTo1 & F1.Name, True
	   Fso.DeleteFolder(F1.Path),True 
	 End If 
	 If InStr(LCase(File.Path),".mkven
	  Set F1 = Fso.GetFolder(Fso.GetParentFolderName(File.Path))
	   Fso.CopyFolder F1.Path, CopyTo1 & F1.Name, True
	   Fso.DeleteFolder(F1.Path),True 
	 End If 
	Next
	Dim Obj
	For Each Obj In Folder.subFolders
	 Recursive Obj
	Next
   End Function
'-> End Of Script Message 
   MsgBox "Completed Movies Moves",4128,"Finished"
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.