How to replace all spaces by underscores in all file names of a folder?

后端 未结 8 2316
鱼传尺愫
鱼传尺愫 2020-12-07 18:50

I\'m trying to rename all the files inside a folder (all .exe files). I want to replace all the spaces with underscores, e.g. qwe qwe qwe asd.exe to qwe_q

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-07 19:30

    Save the following 2 commands in a .bat file. It will replace " " with "_" in all files and folders, recursively, starting from the folder where the file is stored.

    forfiles /s /m *.* /C "cmd /e:on /v:on /c set \"Phile=@file\" & if @ISDIR==FALSE ren @file !Phile: =_!"
    forfiles /s /C "cmd /e:on /v:on /c set \"Phile=@file\" & if @ISDIR==TRUE ren @file !Phile: =_!"
    

    Note: First line is doing this for files, and second one is doing this for folders. Each line can be used separately.

提交回复
热议问题