How to remove spaces from file names (in bulk)

前端 未结 6 2146
无人及你
无人及你 2020-12-04 19:51

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:

fi         


        
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 20:33

    You can write a simple script that does this for one file/directory, e.g.:

    @echo off
    setlocal enableextensions enabledelayedexpansion
    
    set "ARG=%~1"
    ren "%ARG%" "%ARG: =%"
    

    ...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:

    for %f in (*) do @myrenamingscript.cmd "%~f"
    

提交回复
热议问题