New
#1
How to add containing folders to collection of files
I have several thousand files that I want put into individual folders of the same name. Does anyone know of a batch method for this?
I have several thousand files that I want put into individual folders of the same name. Does anyone know of a batch method for this?
Hello @Fundeby,
Create a Files_To_Folders.bat file with the code below in the directory that the files are in.
This batch script creates a folder for each filename in the directory that the batch script resides in and then populates [ moves ] them with the files accordingly. The folders names will be a mirror image of the filenames themselves, excluding the suffix.
WARNING: Setup a test directory directory that includes a selection of filenames FIRST and then run the batch script to ensure that the results are correct and as expected.
I hope this helps!Code:@echo off title Files To Folders - Written by Paul Black. echo. & echo Processing . . . & echo. for %%i in (*) do ( if not "%%~ni" == "Files_To_Folders" ( md "%%~ni" && move "%%~i" "%%~ni" ) ) echo. & echo ^>Press ANY key to EXIT . . . & pause >nul
Last edited by Paul Black; 03 Jul 2020 at 12:10.
Hello @Lance1,
If you think it will also be useful to have the total number of folders created and the files moved let me know and I will adapt the code accordingly. I can also adapt the code so it doesn't show the long list of 1 file(s) moved..
Last edited by Paul Black; 01 Jul 2020 at 17:20.
Here you go @Lance1,
Please let me know how it works for you [ see Post #4 for warnings and advice ]!Code:@echo off title Files To Folders - Written by Paul Black. set count=-1 echo. & echo Processing . . . for %%j in (*) do set /A Count +=1 for %%i in (*) do ( if not "%%~ni" == "Files_To_Folders" ( md "%%~ni" && move "%%~i" "%%~ni" >nul ) ) echo. & echo Created %Count% folders and moved the files successfully! echo. & echo ^>Press ANY key to EXIT . . . & pause >nul
I hope this helps!