How to remove spaces (not replace with underscores) from several thousand files in bulk in Windows? Can I do this from the DOS command?
Currently:
file one.mp3
file two.mp3
All files need to become:
fileone.mp3
filetwo.mp3
How to remove spaces (not replace with underscores) from several thousand files in bulk in Windows? Can I do this from the DOS command?
Currently:
file one.mp3
file two.mp3
All files need to become:
fileone.mp3
filetwo.mp3
Here is a script that can efficiently bulk rename files, stripping all spaces from the name.
Assume the script is called renameNoSpace.bat
renameNoSpace
: (no arguments) Renames files in the current directoryrenameNoSpace /R
: Renames files in the folder tree rooted at the current directoryrenameNoSpace myFolder
: Renames files in the "myFolder" directory found in the current directory.renameNoSpace "c:\my folder\"
: Renames files in the specified path. Quotes are used because path contains a space.renameNoSpace /R c:\
: Renames all files on the C: drive.You can write a simple script that does this for one file/directory, e.g.:
...and then if you'd like, run it over all the files and/or directories you care about. For instance, if you create the above script as myrenamingscript.cmd, you can run it over all non-dir files in the current dir by running:
Create a powershell file -
*.ps1
extensionWrite this code:
save, then right click -> run with powershell
The problem i have faced is that there is a possibility that there is already a file with the name you try to give to the new file (eg if there are 2 files in the folder named "file one.txt" and "file_one.txt" when you try to replace the spaces with underscores, one file will replace the other). So I made this script that checks if the new name already exists and if so places a number at the end of the file name (adds 1 to the number until there is no other file with that name). Instructions about what to change are at the top (commended out lines). Do not store the batch file in the same folder you have the files to be renamed if you use *.* option. I hope this helps.