How to Remove Space of all files in directory



Below steps elaborate you how to remove space of all files in directory

1. Copy all files which you want to rename to a directory . (let us assume directory is c:\Users\Shetty\Desktop\Allfiles\ )

2. Open Notepad & copy below content & save the file in above directory with .bat file extension. (assuming filename rename.bat )

:renameNoSpace  [/R]  [FolderPath]
@echo off
setlocal disableDelayedExpansion
if /i "%~1"=="/R" (
  set "forOption=%~1 %2"
  set "inPath="
) else (
  set "forOption="
  if "%~1" neq "" (set "inPath=%~1\") else set "inPath="
)
for %forOption% %%F in ("%inPath%* *") do (
  if /i "%~f0" neq "%%~fF" (
    set "folder=%%~dpF"
    set "file=%%~nxF"
    setlocal enableDelayedExpansion
    echo ren "!folder!!file!" "!file: =!"
    ren "!folder!!file!" "!file: =!"
    endlocal
  )
)

3. Now open command prompt & go to the Allfiles directory. And run below command

rename.bat /R


Thats it.. All your files which has space will be corrected now. Use below Arguments only if you know what you are doing

rename.bat : (no arguments) Renames files in the current directory

rename.bat /R : Renames files in the folder tree rooted at the current directory

rename.bat myFolder : Renames files in the "myFolder" directory found in the current directory.

rename.bat "c:\my folder\" : Renames files in the specified path. Quotes are used because path contains a space.

rename.bat /R c:\ : Renames all files on the C: drive.

2 comments: