E
emrefan
Guest
I wanted to write a batch file for comparing files in the current
directory with those in another directory in terms of file size. And
the following is what I have so far:
@echo off
rem compare files in the current directory with those in another
directory
rem in terms of file size.
rem parameter to this batch ("the other directory") should include the
path separator
rem (backslash) if it is a proper directory spec rather than say
"<drive letter>:"
if "%1"=="" (
echo Usage %0 the-other-dir
goto :end
)
for %%f in (*.*) do (
set fn=%%f
echo %fn%
set fn2=%1%fn%
echo %fn%
for %%G in (%fn%) do set fz1=%%~zG
for %%H in (%fn2%) do set fz2=%%~zH
echo fz1=%fz1% fz2=%fz2%
)
:end
Now, every time I ran this batch file only things from the stupid to
the absolute insane happened. The results did not make any sense at
all. Sometimes the file sizes were insanely large, sometimes empty,
other times the filenames fetched were those from the last run and
were totally irrelevant to the recent invocation. I think the fact I
am assigning the for loop variable to another variable is making XP go
berserk because if I had the for loop modified to this below things
would appear normal.
for %%f in (*.*) do echo %%~zf
But of course that's not gonna get my job done.
directory with those in another directory in terms of file size. And
the following is what I have so far:
@echo off
rem compare files in the current directory with those in another
directory
rem in terms of file size.
rem parameter to this batch ("the other directory") should include the
path separator
rem (backslash) if it is a proper directory spec rather than say
"<drive letter>:"
if "%1"=="" (
echo Usage %0 the-other-dir
goto :end
)
for %%f in (*.*) do (
set fn=%%f
echo %fn%
set fn2=%1%fn%
echo %fn%
for %%G in (%fn%) do set fz1=%%~zG
for %%H in (%fn2%) do set fz2=%%~zH
echo fz1=%fz1% fz2=%fz2%
)
:end
Now, every time I ran this batch file only things from the stupid to
the absolute insane happened. The results did not make any sense at
all. Sometimes the file sizes were insanely large, sometimes empty,
other times the filenames fetched were those from the last run and
were totally irrelevant to the recent invocation. I think the fact I
am assigning the for loop variable to another variable is making XP go
berserk because if I had the for loop modified to this below things
would appear normal.
for %%f in (*.*) do echo %%~zf
But of course that's not gonna get my job done.