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

copy file on filesize condition DOS

Reply to Message Icon

Original Message
Name: masterj
Date: January 30, 2006 at 08:32:24 Pacific
Subject: copy file on filesize condition DOS
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?


Report Offensive Message For Removal

Response Number 1
Name: Mechanix2Go
Date: January 30, 2006 at 23:18:18 Pacific
Subject: copy file on filesize condition DOS
Reply: (edit)

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


Report Offensive Follow Up For Removal

Response Number 2
Name: masterj
Date: January 31, 2006 at 04:20:36 Pacific
Subject: copy file on filesize condition DOS
Reply: (edit)

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?


Report Offensive Follow Up For Removal

Response Number 3
Name: Mechanix2Go
Date: January 31, 2006 at 04:55:37 Pacific
Subject: copy file on filesize condition DOS
Reply: (edit)

Hi mj,

I'm working on it.

:)


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

M2


Report Offensive Follow Up For Removal

Response Number 4
Name: Mechanix2Go
Date: February 2, 2006 at 02:22:10 Pacific
Subject: copy file on filesize condition DOS
Reply: (edit)

I'm still at it.


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

M2


Report Offensive Follow Up For Removal

Response Number 5
Name: masterj
Date: February 2, 2006 at 05:52:17 Pacific
Subject: copy file on filesize condition DOS
Reply: (edit)

any progress with this? :)


Report Offensive Follow Up For Removal


Response Number 6
Name: Mechanix2Go
Date: February 3, 2006 at 05:40:35 Pacific
Subject: copy file on filesize condition DOS
Reply: (edit)

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


Report Offensive Follow Up For Removal

Response Number 7
Name: masterj
Date: February 3, 2006 at 07:20:31 Pacific
Subject: copy file on filesize condition DOS
Reply: (edit)

:)

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


Report Offensive Follow Up For Removal

Response Number 8
Name: Mechanix2Go
Date: February 3, 2006 at 10:02:47 Pacific
Subject: copy file on filesize condition DOS
Reply: (edit)

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


Report Offensive Follow Up For Removal

Response Number 9
Name: masterj
Date: February 5, 2006 at 07:08:09 Pacific
Subject: copy file on filesize condition DOS
Reply: (edit)

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


Report Offensive Follow Up For Removal

Response Number 10
Name: Mechanix2Go
Date: February 6, 2006 at 00:35:54 Pacific
Subject: copy file on filesize condition DOS
Reply: (edit)

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


Report Offensive Follow Up For Removal

Response Number 11
Name: masterj
Date: February 6, 2006 at 04:02:25 Pacific
Subject: copy file on filesize condition DOS
Reply: (edit)

hard one, huh? :)


Report Offensive Follow Up For Removal

Response Number 12
Name: Mechanix2Go
Date: February 6, 2006 at 04:42:52 Pacific
Subject: copy file on filesize condition DOS
Reply: (edit)

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


Report Offensive Follow Up For Removal

Response Number 13
Name: masterj
Date: February 7, 2006 at 10:55:42 Pacific
Subject: copy file on filesize condition DOS
Reply: (edit)

more like a 5oo mb to me :)

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


Report Offensive Follow Up For Removal






Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: copy file on filesize condition DOS

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software