multiple files to move into their own folder

February 9, 2011 at 13:16:01
Specs: XP, +4400
Hi all. I have 500+ video files and I want to move them into new folders of the same name. Is there any easy way to do this? It is time consuming to copy file name, create folder, change folder name and then move the video file into that help will be appreciated. Cheers.

See More: multiple files to move into their own folder

Report •

February 9, 2011 at 15:58:58
You might want to ask this question over in the Programming Forum,
I'm sure they can whip you up a batch file that will do what you want.


Report •

February 9, 2011 at 16:10:16
so does that mean there s nothing out there now? I am no good with playing around with system files...I need something easy to work with.

Report •

February 9, 2011 at 16:25:19
While this is not really an "Excel project", VBA has the ability to do what you want.

The following code is a combination of snippets I've found on the web and have used in the past for various projects. It appears to do what you want, based on the assumptions listed below.

Obviously I don't have your folders or paths to work with, so you are going to have to modify some of the path strings to match your specific situation.

Assumptions (the way it worked for me)

1 - All files to be moved are in a folder on my Desktop named VidSrc
2 - All files have a 3 letter extension e.g. .xxx In order to create a folder based on the File Name, I strip off the last 4 characters of the File Name e.g. .xxx
3 - All folders will be created in a folder on my Desktop named VidDst. After each folder is created, the file will be moved from VidSrc to the newly created folder. VidDst must exist on the Desktop before the code is run.
4 - The File Names can't have any characters in them that would prevent the name from being used as a Folder name.

I suggest that you create a folder called VidSrc that contains copies of a few of your videos to test this with. It should only move the files to VidDst, but I can't take any blame if something goes terribly wrong.

To run the code, follow these steps:

1 - Open an Excel workbook
2 - Press Alt-F11 to open the VBA editor
3 - Click on Insert...Module
4 - Copy and paste all of the code below into the pane that opens
5 - Modify the paths to match your paths
6 - At the top of the window, click on Tools...References
7 - If you don't see Microsoft Scripting Runtime as one of the references checked at the top of the list, scroll down to Microsoft Scripting Runtime and place a check mark next to it and then click OK.
8 - Click inside the MoveAllFiles macro to place the flashing cursor anywhere inside that section of code.
9 - Press F8
10 - Assuming you get no errors, press F8 a couple of more times until the yellow line jumps down into the MoveFiles macro section.
11 - Keep pressing F8 through at least one loop to see if any errors pop up.
12 - If you don't get any errors, check the VidDst folder to see if a folder was created and a file moved.
13 - If everything looks OK, go back into the VBA editor and either continue to press F8 to Single Step through the code or press F5 to let it run on it's own until done.

I'm sure you'll have questions, so come on back when you do. Good luck!

Public FsO As FileSystemObject

'Trigger Sub - Run Me
Sub MoveAllFiles()
  Set FsO = New FileSystemObject
  MoveFiles FsO.GetFolder("C:\Documents and Settings\DerbyDad03\Desktop\VidSrc")
  Set FsO = Nothing
End Sub

'Master function
Public Sub MoveFiles(fldr As Folder)
Dim fiL As File
'Loop through Files
   For Each fiL In fldr.Files
'Create folder from file name with 3 letter extension
     MkDir "C:\Documents and Settings\DerbyDad03\Desktop\VidoDst\" & _
               Left(fiL.Name, Len(fiL.Name) - 4)
'Set path to move file from
     StrMoveFrom = fiL.Path
'Set path to move file to
     StrMoveTo = "C:\Documents and Settings\DerbyDad03\Desktop\VidDst\" & _
                   Left(fiL.Name, Len(fiL.Name) - 4) & "\"
'Move the file
      FsO.MoveFile StrMoveFrom, strMoveTo
End Sub

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.

Report •

Related Solutions

February 26, 2011 at 23:13:34
Looks like a nice way to do it...but the 500+ (Its actually 800 files) add up to a larger size than available space on the PC.
800 files = 844 Gb
Desktop space = 20 Gb

I am surprised there are no programs or windows add ons that are capable of this.

Report •

June 17, 2011 at 14:31:51
Hello DerbyDad03

Your script is excellent !!!
I am new to programming field and wish if you could help me too.
Could you plz write or modify the above script to move 3 files (same name with different extensions) to a folder with name from file?

For eg. I have
These files need to go to a folder named div.

Similarly, there are many others like;
These files need to go to a different folder named william.
I have 1000s of those and need to automate the process.


Report •

July 31, 2011 at 00:39:47
try this in batchfile for windows

@echo off
for %%a in (*.*) do (
md "%%~na" 2>nul
move "%%a" "%%~na"

Report •

August 12, 2011 at 04:18:50
i checked your code

"try this in batchfile for windows

@echo off
for %%a in (*.*) do (
md "%%~na" 2>nul
move "%%a" "%%~na"
it created folders for every single file.

can you modify it to create folders for two-or-more files pleasE?

Report •

Ask Question