I have a folder which contains 4 sub folders and in each of these 4 folders there are more folders that contain images.

I need to replace all the spaces in the image names with hyphens e.g.

blue magazine.jpg would become blue-magazine.jpg

Is there any way I can do this using a batch file / some free software / via command prompt or any other ways?



Try using for.

for /f "tokens=1,2,3" %i in ('dir /b /s *.jpg') DO move "%i %j" "%i-%j"

This would replace spaces with hyphens in .jpg files in the current directory and subdirectories.


I do all my scripting work using linux bash. This way knowing one scripting language is enough. To have it on Windows, install MSYS. Then use commands find with -exec clause and mv.

I install MSYS also in Windows server environments, without problems. Actually the installation process is not necessary. It runs simply after copying the files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy