所以我找到了这个很棒的脚本,它将帮助我删除文件名空间,但我有200多个文件所在的子文件夹,需要在目录中的所有子文件夹上运行命令。这有可能吗?我该怎么做。现在我知道的命令是' myScript \ R C:\ somedir \ somedir \ rootprojectfolder \'但这似乎不起作用。
: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
)
)
答案 0 :(得分:1)
myScript /R "C:\somedir\somedir\rootprojectfolder"
使用指定的斜杠并引用路径以防止出现空格和特殊字符问题
另外请记住,如果文件夹下有某个文件/文件夹正在使用中,则无法重命名文件夹
已编辑以适应评论 - 更新代码以处理文件和文件夹
: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="
)
set "doFolders="
:iterate
for %doFolders% %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
)
)
if not defined doFolders ( set "doFolders=/D" & goto :iterate )