Computing.Net > Forums > Programming > copy file on filesize condition DOS

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

copy file on filesize condition DOS

Reply to Message Icon

Name: masterj
Date: January 30, 2006 at 08:32:24 Pacific
OS: winxp
CPU/Ram: 512
Comment:

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?



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: January 30, 2006 at 23:18:18 Pacific
Reply:

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


0

Response Number 2
Name: masterj
Date: January 31, 2006 at 04:20:36 Pacific
Reply:

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?


0

Response Number 3
Name: Mechanix2Go
Date: January 31, 2006 at 04:55:37 Pacific
Reply:

Hi mj,

I'm working on it.

:)


If at first you don't succeed, you're about average.

M2


0

Response Number 4
Name: Mechanix2Go
Date: February 2, 2006 at 02:22:10 Pacific
Reply:

I'm still at it.


If at first you don't succeed, you're about average.

M2


0

Response Number 5
Name: masterj
Date: February 2, 2006 at 05:52:17 Pacific
Reply:

any progress with this? :)


0

Related Posts

See More



Response Number 6
Name: Mechanix2Go
Date: February 3, 2006 at 05:40:35 Pacific
Reply:

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


0

Response Number 7
Name: masterj
Date: February 3, 2006 at 07:20:31 Pacific
Reply:

:)

Hi M2Go!

I've tried batch with folders
D:\Music\test1 and D:\Music\test2

but batch doesn't copy files.

Now my batch looks like this:

::== movebigr.bat
@echo off
cls

setlocal
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


0

Response Number 8
Name: Mechanix2Go
Date: February 3, 2006 at 10:02:47 Pacific
Reply:

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


0

Response Number 9
Name: masterj
Date: February 5, 2006 at 07:08:09 Pacific
Reply:

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...


0

Response Number 10
Name: Mechanix2Go
Date: February 6, 2006 at 00:35:54 Pacific
Reply:

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


0

Response Number 11
Name: masterj
Date: February 6, 2006 at 04:02:25 Pacific
Reply:

hard one, huh? :)


0

Response Number 12
Name: Mechanix2Go
Date: February 6, 2006 at 04:42:52 Pacific
Reply:

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


0

Response Number 13
Name: masterj
Date: February 7, 2006 at 10:55:42 Pacific
Reply:

more like a 5oo mb to me :)

ok, i'll send you some files as fast as i get my hands on my laptop :)


0
Reply to Message Icon

Batch File To alter a .in... Extract IP address from t...



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: copy file on filesize condition DOS

batch copy file on Ping Errorlevel= www.computing.net/answers/programming/batch-copy-file-on-ping-errorlevel/18016.html

copy file on reboot in xp? www.computing.net/answers/programming/copy-file-on-reboot-in-xp/19095.html

Windows Batch + C++ to copy files? www.computing.net/answers/programming/windows-batch-c-to-copy-files/6254.html