Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I've been working around on a batch which compares to file sizes. And if first file size is bigger, batch copies it over the second file and overwrites it.
I've wrotten few lines of code, but it doesn't seem to work:
set /p PATH=c:\music
for /f %%a in ('dir /b "%PATH%\RENAMED"') do (
if not exist "%PATH%\RENAMED\%%a" (
copy /-Y "%PATH%\RENAMED\%%a" "%PATH%\BIG COLLECTION [NORMALIZED]"
) else (call "%PATH%\RENAMED\%%a"
%~z1>"%PATH%\size1.txt"
set /a size1=<"%PATH%\size1.txt"
del /q "%PATH%\size1.txt"call "%PATH%\BIG COLLECTION [NORMALIZED]\%%a"
%~z1>"%PATH%\size2.txt"
set /a size2=<"%PATH%\size2.txt"
del /q "%PATH%\size2.txt"if %size1%>%size2% (
copy /-Y "%PATH%\RENAMED\%%a" "%PATH%\BIG COLLECTION [NORMALIZED]"
)
)
)
Any ideas?

First, I guess you want to use XP; not DOS.
Second, it's probably a bad idea to have a batch alter the PATH variable unless you have a very good reason for it to do so.
Next, to set a var, the
set /p myVAR=
is used to get user input.
If you simply want to set a var, the syntax is:
set myVAR=mySTRING
Once you hammer that out, let's see where you are in the process of comparing sizes.
If at first you don't succeed, you're about average.M2

Hi Machanix2Go :)
Maybe you could give me a batch example, which could compare files from two directories and if some of the files don't exist in the second dit, just move them from first dir to the second dir. If file exist in second dir with same name as in first dir and if file in first directory is bigger than in the second directory, batch could move file from first dir to second dit, overwriting original file from second dir?

Try this:
::== movebigr.bat
@echo off
setlocal
for /f %%F in ('dir/s/b first') do call :sub1 %%F
goto :eof:sub1
set SRC=%1
set sizeSRC=%~z1
set SRCname=%~nx1
set DEST=second
set sizeDEST=if not exist second\%SRCname% echo move /y %SRC% %DEST% && goto :eof
if exist second\%SRCname% call :D
if %sizeSRC% GTR %sizeDEST% echo move /y %SRC% %DEST%
goto :eof:D
echo second\%SRCname%>#
set /p DEST=<#
del #
call :sizer %DEST%
goto :eof:sizer
set sizeDEST=%~z1
goto :eof
:: DONE
It is hardwired to use directories named:first
second
If at first you don't succeed, you're about average.M2

:)
Hi M2Go!
I've tried batch with folders
D:\Music\test1 and D:\Music\test2but batch doesn't copy files.
Now my batch looks like this:
::== movebigr.bat
@echo off
clssetlocal
for /f %%F in ('dir /s /b "D:\Music\test1"') do call :sub1 %%F
goto :eof:sub1
set SRC=%1
set sizeSRC=%~z1
set SRCname=%~nx1
set DEST=D:\Music\test2
set sizeDEST=if not exist "D:\Music\test2\%SRCname%" echo move /y %SRC% %DEST% && goto :eof
if exist "D:\Music\test2\%SRCname%" call :D
if %sizeSRC% GTR %sizeDEST% echo move /y %SRC% %DEST%
goto :eof:D
echo "D:\Music\test2\%SRCname%">#
set /p DEST=<#
del #
call :sizer %DEST%
goto :eof:sizer
set sizeDEST=%~z1
goto :eof
:: DONE

Hi mj,
I neglected to mention that as posted, the BAT doesn't *DO* anything.
It puts out [ECHOs] lines like
move /y C:\temp\-\bigger\first\M3.BAT second\M3.BAT
To "activate" it so that it actually does the MOVE, you need to edit out the ECHO preceeding the MOVE.
Try that and see if it works.
If not, we may need to deal with the "".
If at first you don't succeed, you're about average.M2

OK :) i've opened it trough cmd.exe to see what it shows...
If filename contains a space batch shows only first word of file name and even no file extension...

Hi mj,
The firat time I did a DIR on a 95 drive and saw progra~1, I knew we were in for a rough ride. Funny file names are best left to a real OS.
Gimme a couple days and I'll try to hammer it out.
If at first you don't succeed, you're about average.M2

Hi mj,
Could you zip up some files with the relevant lines?
ou can bleep out anything that's sensitive, as long as I get a handle on the contents.
AND, rename it mj.z because I block all ZIPs.
email it to me.
If it's more than a few MB use www.yousendit.com
If at first you don't succeed, you're about average.M2

more like a 5oo mb to me :)
ok, i'll send you some files as fast as i get my hands on my laptop :)

![]() |
Batch File To alter a .in...
|
Extract IP address from t...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |