1.

Solve : About fetching files in folder whose name containing blank?

Answer»

Below is my program for comparing files in two folders. It works well if no space character exists in folder names. But if there is a space in folder name, it goes wrong from loop of "FOR /d %%H in (*) DO ". I tested this program with c:\av1\11 vs c:\av1\22. There is a sub-folder "kk yy" under c:\av1\11.
In case of "kk yy" being empty, after showing "files done, then subdir", it shows
"to compare %~fH :::: c:\av1\22\kk yy\%~nxH"
"The follwing usage of the path operator in batch-parameter substitution is invalid: %~fH" "C:\av1\22\kk yy\%~nxH"
In my opinion, it shouldn't show "to compare ...." for folder "kk yy" is empty. No any iteration should be executed, I think.

In case of "kk yy" containing a file "0000", it shows
"c:\av1\11\kk yy\0000 ++++ c:\av1\22\kk yy\0000
"The system cannot find the path specified"

Is there any way to conquer the issue from folder containing SPACES?


:cmpdir dir1 dir2
setlocal enabledelayedexpansion

@echo on
pushd %2
@echo off

for /f "delims=" %%A in ('cd') do set dir2=%%A
popd

echo %1 ***vs*** %2

pushd %1
echo to compare file first
FOR %%G in (*) DO (
echo file: %%G
echo %%~fG ++++ %dir2%\%%~nxG
if not exist %dir2%\%%~nxG (
echo file %dir2%\%%~nxG disappeared
goto :cmpdir_err
)
fc /b **~fG %dir2%\**~nxG > nul
if !ERRORLEVEL! neq 0 (
echo file %dir2%\%%~nxG corrupted
goto :cmpdir_err
)
)
echo files done, then subdir
FOR /d %%H in (*) DO (
echo === to enter %%~fH
if not exist %dir2%\%%~nxH (
echo folder %dir2%\%%~nxH disappeared
exit /b 255
)
echo to compare %%~fH :::: %dir2%\%%~nxH
call :cmpdir "%%~fH" "%dir2%\%%~nxH"
if !errorlevel! equ 255 goto :cmpdir_err
)
:cmpdir_ok
popd
exit /b 0

:cmpdir_err
popd
exit /b 255Try putting the file names in quotes.It doesn't work.



Discussion

No Comment Found