在我的程序中,我从一堆文件夹中提取文件名,其中一些文件夹有空格。我试过用引号设置它们。我试过把套装放在引号中。我试过延迟扩张。到目前为止,我已经尝试了所有我能找到的东西。
目前的相关代码是:
SET "FTPFOLDER=C:\temp"
REM THIS GOES THROUGH THE FILE SYSTEM INITIALLY.
pause
for /f "delims=" %%f in ('dir /b "%FTPFOLDER%"') do (call :Search "%%f")
pause
REM GOES THRU EACH OF THE FILES IN EACH OF THE FOLDERS. IF THE FILE READ IS A FOLDER, IT GOES SEARCHES DEEPER INTO THE FOLDER.
:Search
setlocal enabledelayedexpansion
for /f "delims=" %%g in ('dir /b "%FTPFOLDER%\%~1"') do (if exist "%FTPFOLDER%\%~1\%%g\*" (
set nsearch =%~1\%%g
call :Search !nsearch!
) else (
set filedir = %FTPFOLDER%\%~1\%%g\
set filename = %%~ng
call :checkSize !filedir!, !filename!
)
)
pause
EXIT /B 0
REM CHECKS IF ZERO
:checkSize
pause
set file="%~1"
@echo %file%
for /f "usebackq" %%h in ('%file%') do (set size=%%~zh)
if %size% EQU 0 (call :Rename "%file%", %~2)
pause
EXIT /B 0
REM - RENAMES FILE TO .EMPTY
:Rename
pause
ren %~1 %~2.empty
pause
EXIT /B 0
我老老实实地尝试了我所见过的所有内容,而且没有任何效果。非常感谢任何和所有的帮助!