开发者

windows script for delete white space from file name

开发者 https://www.devze.com 2023-03-07 19:27 出处:网络
I wrote a script that clear white space开发者_JS百科s and write it to the console, but infact do nothing to file name -

I wrote a script that clear white space开发者_JS百科s and write it to the console, but infact do nothing to file name -

@echo off&setlocal EnableDelayedExpansion
for /f "tokens=*" %%A in (
'dir C:\Inetpub\ftproot\MG_REPORTS\MG_PRO_\Network\Frank\ "* *"'
) do (set XX=%%~nxA)&echo ren "%%A"  "!XX: =!"

regards,

shamie


Your for loop only sets XX to the last file name encountered. Also it probably loops over all files in the given directory and all file names containing spaces in the current working directory.

I'd do it the following way:

setlocal enabledelayedexpansion
for %%f in (C:\Inetpub\ftproot\MG_REPORTS\MG_PRO_\Network\Frank\*) do (
   set "FN=%%~nxf"
   set "FN=!FN: =!"
   ren "%%f" "!FN!"
)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号