Auto create folder based on filename and move the file into it's folder
This is a Windows batch script that creates folders for each file in the current folder that the script is running. The folders are created with folder names that follow the filenames. After creating the folder, it will move the file into it's own folder. This batch script is particularly useful in organizing files into it's own folder.
Step 1 : Copy the Windows batch code below into your notepad and save it with filename "organize.bat".
Step 1 : Copy the Windows batch code below into your notepad and save it with filename "organize.bat".
@echo off
for %%i in (*) do (
if not "%%~ni" == "organize" (
md "%%~ni" && move "%%~i" "%%~ni"
)
)
Step 2 : Copy organize.bat file to the folder where there are files that you want to organize each file to be copy into a folder which has the same name as the filename.
Step 3 : Double click organize.bat file and watch the magic begins.
Worked beautifully for me - thanks!
ReplyDeleteAlso please note that this script does not create the folders with file extensions included (e.g. filename.txt does not create a folder "filename.txt" but just "filename"). Worked perfect for what I needed.
Thanks! Glad you find it useful.
DeleteHi Boon! Thank for your batch, seems to work great!
DeleteCan it be modified to do the following:
Filenames that start from 22 ("22.*") create a new folder called "22" and move them there.
And filenames that start from ("40.*") create a new folder called "40" and move them there.
Thank you so much for your time to answer me!
Hi Boon ! thank you for the batch file & the code. really works like magic. very helpful. Just like you - a Boon :)
DeleteJust in case you like to rename it after copying, mine i need to change it to game.iso
Delete@echo off
for %%i in (*) do (
if not "%%~ni" == "Organizer.bat" (
md "%%~ni" && move "%%~i" "%%~ni" && ren "%%~ni\%%~i" "game.iso"
)
)
pause
Hi, hoping you get this message as this post is a couple of years old. Is there a way to modify your script to move multiple files into 1 folder (bin/cue files)
Deleteamazing....you saved a lot of time for me.
ReplyDeleteprefect script for creating folder and moving file name.
You are a life saver. Thank you very much man.
ReplyDeleteThank you. Worked like magic
ReplyDeleteI am using Windows 10 and I can't get the .bat file to work. Should I save it as ANSI or UNICODE? Both doesn't work...
ReplyDeleteplace your code into a notepad file1 Save it as a text file while your working on it. them make a copy but save it a .bat file. The next time you click the .bat file it will run using Dos.
DeleteTHANK YOU - This is brilliant and as everyone else says, a true time saver.
DeleteI hope you can help me a little further please?
I'm moving lots of music files into folders, Each file has an artist then a hyphen and then the title (Beatles - Hey Jude, Beatles - Please Please Me, Rolling Stones-Brown Sugar, Rolling Stones - The Last Time etc.)..
How can I modify the bat file to create the folders just by the characters to the left of the first hyphen please? Example is that I have many files with Beatles, Rolling Stones etc. to the left of the hyphen and so many track names to the right. If there is a way to create a Beatles folder and then move all their songs into it please, then the same with Rolling Stones and other artists? All the song files can stay named as they are, it's just getting them into a single folder.
Many thanks in advance, Nigel.
Thank you very much, but is there a way to make the BAT file not be moved Into a folder?
ReplyDeleteName the file as "organize", if you want to rename it to something else, then open that .bat file and change the word "organize" to the name of that file. I hope this helped.
DeleteName the file "organize"
DeleteI had the same issue. I think it was because I wrongly using a uppercase "o" in the filename (i.e., "Organize.bat" vs. "organize.bat".
DeleteMay many good be with you because of this valuable information.
ReplyDeleteThanks, Very Helpful.
simply amazing, and I make sure no adblocker for you page (while listed)
ReplyDeleteWow you really helped me a lot.. TFS!
ReplyDeleteI need 0001A.jpg, 0001B.jpg... move to folder 0001
ReplyDeletePlease help me!
I need 0001A.jpg, 0001B.jpg... move to folder 0001
ReplyDeletePlease help me!
Thankss!!!!!!!!!!!!!
ReplyDeleteThanks so much, saved me so much time!
ReplyDeleteHI BOON SEONG, GREAT PROGRAM. IT HELPED US LOT.
ReplyDeletethanks
ReplyDeleteAmazing script, saved me a couple of hours work at least :)
ReplyDeleteMaaaan , You're Genius.
ReplyDeletei want new new folder same as file name but it should be first 3 letters of file . pls help
ReplyDeletei have the same problem, i don't wanna the full name on the folder just first 9 letters of file, how can i change the code to do this ?
Deletei have the same problem, i don´t wanna full name in the folder, how can i change the code to do this ?
DeleteDoesn't seem to work on Windows 10. Even running as admin.
ReplyDeleteThat means you don't have administrative privileges.
DeleteDoesn't seem to work on Windows 10. Even running as admin.
ReplyDeleteSame here, says access denied
DeleteSadly, does not work, Access Denied as stated above. Windows 10 Enterprise.
Deletethanks a lot
ReplyDeleteHi, I need urgent help to sort files, and this blog is the only one where I found something similar to my problem.
ReplyDeleteI have the following files:
[WhatsApp] Image 2020-02-27 at 17.29.28.jpeg
[Chrome] methods.jpg
And then I need a new folder to be created using the name in the two brackets at the beginning. It doesn't matter if the folder includes the brackets or not. Example:
[Chrome]
[Whatsapp]
Thanks .. i used this to organize files with same name and different extensions in the same folder.
ReplyDeleteI tried this with same names and different extensions on some of the files but didn't work - it just ignored the 2nd file it came across?
DeleteYes! it does create folder names from filename, anyfile1.xxx anyfile2.xxx etc & move those files to the corresponding folders,
ReplyDeleteBUT it also moves the batch file to its own named folder, an unfortunate unexpected side effect, which can be managed - once you're aware its going to happen.
Thank you so much... Saved me a lottt of my time....
ReplyDeleteWorked perfectly on Windows 10 Enterprise! Thanks so much for this life saving solution. :-)
ReplyDeleteI have a list of files in a folder upon running a batch as below
ReplyDelete@echo off
for %%i in (*) do (
if not "%%~ni" == "organize" (
md "%%~ni" && move "%%~i" "%%~ni"
)
)
It will create a folder each for the file and move that file to respective folder.
My requirement is:
I will have list of files in a folder, also I will have a csv /excel sheet in which I will have 2 columns 1. File Id 2. File Name (It is same file names which are in the folder).Now I want to create a folder for each file but I want to name the folder with the File Id which is in CSV which maps with the file name.
I have a list of files in a folder upon running a batch as below
ReplyDelete@echo off
for %%i in (*) do (
if not "%%~ni" == "organize" (
md "%%~ni" && move "%%~i" "%%~ni"
)
)
It will create a folder each for the file and move that file to respective folder.
My requirement is:
I will have list of files in a folder, also I will have a csv /excel sheet in which I will have 2 columns 1. File Id 2. File Name (It is same file names which are in the folder).Now I want to create a folder for each file but I want to name the folder with the File Id which is in CSV which maps with the file name.
Beautiful. Thanks!
ReplyDeleteWorked beautifully for me - thanks!
ReplyDeleteAlso please note that this script does not create the folders with file extensions included . Worked perfect for what I needed.
Thanks man!
ReplyDeleteThank you sooooooooooooooooo much!!! This script is super helpful :)
DeleteWorks ! Thank You !
ReplyDeleteThanks, this did exactly what I needed. Very grateful.
ReplyDeleteIs there any chance of making this work with mouse right-click option on file(s) and "send to folder with same filename" ??
ReplyDeleteIt is creating only folders not moving files under it
ReplyDeleteIf anybody has problems with the bat file being put insided a folder, that's because the name of the bat need to match the name inside the actual code, IT'S CASE SENSITIVE, to have it to work with the code written above in step 1, you need to call the bat organize.bat not Organize.bat
ReplyDeleteIs there a powershell command that does the same?
ReplyDeleteLets say that I have 100 pictures files in one folder. and they are all different names.
ReplyDeleteand I want to make each folder with same file names group.
All file names are like this:
tiger(1), tiger(2), tiger(3), tiger(4)......tiger(10)
lion(1), lion(2), lion(3)....lion(6)
horse(1), horse(2), horse(3)
pig(1), pig(2), pig(3), pig(4), pig(5)
I want to make auto folder with folder name tiger and it has tiger(1)....tiger(10)
another folder called lion and it has files lion(1)....lion(6)
something like this.
When I run this script, it creates folder with every single file names.
Folder goes like tiger(1) another folder goes tiger(2)..
How can I auto create auto folders with same name group?
shows access denied... tried disabling kaspersky and giving full control to bat file under the properies tab...but no luck
ReplyDeletethanks, works like magic
ReplyDeleteThanks - BIG time saver - worked perfectly!
ReplyDeleteI have a huge request!
ReplyDeleteHow can i configure this to create folders by author from a file?
I have files - in properties is the "author" tag.
i want to create folders with Authors name and inside add all files of each author.
Is this possible?
Thanks so much for this solution!
ReplyDeleteThanks you for the bat file! :)
ReplyDeleteThank you, exactly what I was searching for. Worked perfectly for my need. :-)
ReplyDeleteI ran this script on a network drive (NAS), it did not work, do i need any special command lines, i do have an admin rights on this laptop, i browsing to my NAS and running this script but it does not create any folder, please help!
ReplyDeleteNo special configurations needed. Just make sure you run from the same directory where the files need to be processed and it is on MS Windows.
DeleteI was looking for this for my NAS and it worked beautifully.
same issue here
DeleteThis is simple and very useful. Could you tell me how to have it not transfer over punctuation to the folder name? so if the filename is file.name.zip, the folder will just be file name and not file.name.
ReplyDeleteThank you.
Any solution for Win10/11 users? I'm getting the access denied error when I run the batch, as others have mentioned before.
ReplyDeleteAny work around would be GREATLY appreciated.
Thanks for this I had over 2000 movies on a 14TB hard drive and I wanted to move them into separate folders to use with kodi and your script saved me days of work.
ReplyDeleteNow i just need a script that deletes everything after the date, so
Melancholic.(2018).720p.BluRay.x264.AAC-YTS.MX would just become Melancholic.(2018) or
Minyan.2020.WEBRip.x264-ION10 would change to Minyan.2020 do you know anyway to do this or point me to somebody that might know.
I made something in Powershell for the same purpose
ReplyDelete$BasePath = "C:\Temp\test"
$FilesGreaterThen = 1MB
$MoveAllFilesToRoot = $True
$AllFiles = Get-ChildItem -Path $BasePath -Recurse -File | Where-Object {$_.Length -Gt $FilesGreaterThen}
$AllFiles | ForEach-Object {
$File = ($_.DirectoryName + "\" + $_.Name)
If($MoveAllFilesToRoot) {
$Directory = ($BasePath + "\" + $_.BaseName)
} Else {
$Directory = ($_.DirectoryName + "\" + $_.BaseName)
}
New-Item -ItemType Directory -Force -Path $Directory
Move-Item -Path $File -Destination $Directory
If(-Not(Test-Path($_.DirectoryName + "\*"))) { #Delete source directory if empty
Remove-Item -Path $_.DirectoryName
}
}
a-w-e-s-o-m-e
ReplyDeleteHi there
ReplyDeleteI'm wondering how I could change this script so that it creates the folder names using the first 7 characters of the file names?
Can you advise?
cheers
Kaz
hi Kazb can you send me the script please
Deleteawesome, cheers dude
ReplyDeleteIt did exactly what I wanted. You have saved me a lot of time, and I just wanted to take a moment to say thank you.
ReplyDeleteA big thank you! Great solution, works perfectly.
ReplyDeleteTHANK YOU, BOON! YOU ARE WONDERFUL!
ReplyDeleteThis is amazing man thanks !!!
ReplyDeleteHello Boom, very nice and useful batch file. Do you know how to get the creation date, EXIF I believe, instead of the file name? That would be the icing on the cake for me to organize my files for a indie movie project. Thanks in advance and have a great day.
ReplyDeleteThank you!!
ReplyDeleteGenius!
ReplyDeleteIt is something really awesome! It saved my days worth of work. Thanks man!!
ReplyDeleteHope that someone is still monitoring this !! This works great and would like to ask if someone could provide the batch code for a little bit of a mod. Have a bunch of files based on names+date like "JohnSmith03052022" and "JohnSmithe05162021". Would like to create a directory called "JohnSmith" then move all names containing "JohnSmith" into that directory. Is that possible?
ReplyDeleteLook for a program called ROBOBASKET - That will do the job for you; but it's not free.
DeleteHope someone is still monitoring this thread ! Would like to know if someone can provide the batch code for a slight modification. I have files with a naming convention of "UserName+Date". For instance "JohnSmith09232019" and "JohnSmith02312021". Would like to move all files containing "JohnSmith" into a folder named "JohnSmith". Is that something that is possible? I'm not sure of what variable would work in the code. Would appreciate advice !
ReplyDeleteWorks fantastically. Thanks!
ReplyDeleteW O N D E R F U L! Thank you so much!
ReplyDeletethanks!
ReplyDeleteHonestly you are awesome. This is an incredible time saver!
ReplyDeleteDamn impressed. thanks a tonne, works like magic <3
ReplyDeletei DO NOT REPLY MOSTLY BUT THIS IS LIKE A MIRACLE FOR A SUPER LAZY PERSON LIKE ME HAHA THANK YOU SO MUCH
ReplyDeleteThanks so much! Blessings to you!
ReplyDeleteYOU SIR ARE AN EFFING HERO, I have never ever commented on smt but this one is a hidden gem <3
ReplyDeletesaves time and works like magic ... May God Bless You man
ReplyDeleteholy crap... it actually worked...
ReplyDeleteThanks. I just put all my saved films into individual folders, to stop them auto-playing through.
ReplyDeleteThanks for the code! I edited the code as I needed a variation. I used this to create a folder with the same name for each file, but don't move the original file.
ReplyDelete@echo off
for %%i in (*) do (
if not "%%~ni" == "organize" (
md "%%~ni"
)
)
Thanks again!