Computing.Net > Forums > Programming > Simple CRC in a Batch File

Simple CRC in a Batch File

Reply to Message Icon

Original Message
Name: pball
Date: January 12, 2007 at 13:09:00 Pacific
Subject: Simple CRC in a Batch File
OS: Win XP
CPU/Ram: AND Athlon 2900+ 2 GHz 51
Model/Manufacturer: Home made
Comment:

Hi
I'm sending files to a friend that have been split using a program and they are joined back together by a batch script using copy /b

The thing is I want to add to that script and have it check the file size of all of the files.

First of all I would like the batch file to check if all the files are present.

@echo off
IF EXIST file.1__ (
) ELSE (
echo file.1__ is missing
)

How would I would change this so it would loop and change the file name before it loops
So for example I have 133 pieces, how can I get the number in the file to increase before it loops back? Also the numbering might make this hard since it starts with file.1__ then changes to file.10_ and finally file.100, is there an easy way to erase the"_" from all files before trying to check if they exist?

Then when it has confirmed all the files are present it would check the file size and compare it what it should be
all but the last file is say 10,000,000 bytes and the last one is less, so it would have to check if it is 10,000,000 or the remaining files size.
is there an easy way to get the file size compare it then loop changing the file name to check all of em?
I want to do this all with a batch file since I want to learn more and not have to teach my friend to use any new programs to do this
Thanks


Report Offensive Message For Removal


Response Number 1
Name: Mechanix2Go
Date: January 12, 2007 at 14:18:43 Pacific
Subject: Simple CRC in a Batch File
Reply: (edit)

Something like this:

::== af.bat
for /L %%A in (1 1 10) do (
echo if exist file.%%A* blabla
)
::==

But the final __ will trip things up because 10 and 100 will match 10*.

Maybe much simpler to do a DIR > somefile on your end and his end, then compare.


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

M2



Report Offensive Follow Up For Removal

Response Number 2
Name: pball
Date: January 12, 2007 at 15:27:29 Pacific
Subject: Simple CRC in a Batch File
Reply: (edit)

thanks
i like the compare the dir info idea
Thanks

I searched around here a bit and found how to compare files from one of your posts i believe
is there are way to ignore certain lines when comparing since some files will be differnt, also is there a way when creating the dir output to only output the size and name so the date and time won't throw things off?

this is what i have so far and it works except for the files that will never be the same but i'm using it on the original files so the date and time will be different on his copy

@ECHO OFF

for /f %%i in ("%0") do set curpath=%%~dpi
cd /d %curpath%
dir > crc.txt

@echo off
echo Wscript.Sleep 1000> sleep.vbs
start /w wscript.exe sleep.vbs
del sleep.vbs

fc crc.txt mastercrc.txt > difference.txt

if errorlevel 1 goto :different

goto :join

:different
echo files don't match please send me difference.txt

goto :end

:join
del difference.txt
del mastercrc.txt

::joining happens here

echo file is complete

goto :end

:end
echo this will now close in 5 seconds
del crc.tx
::I usualy replace pause with the timer used above
pause

the first problem is that the dir > output puts the files creation date and time which will mess everything up i believe
the second one is the second last two lines in the crc text files
shown here

Comparing files crc.txt and MASTERCRC.TXT
***** crc.txt

01/12/2007 06:20 PM <DIR> .
01/12/2007 06:20 PM <DIR> ..
01/12/2007 06:20 PM 0 crc.txt
01/12/2007 06:19 PM 5,507 mastercrc.txt
01/12/2007 06:13 PM 544 file beta.bat
***** MASTERCRC.TXT

01/12/2007 06:18 PM <DIR> .
01/12/2007 06:18 PM <DIR> ..
01/12/2007 06:18 PM 0 crc.txt
01/12/2007 06:17 PM 5,507 mastercrc.txt
01/12/2007 06:13 PM 544 file beta.bat
*****

***** crc.txt
77 File(s) 735,639,459 bytes
2 Dir(s) 68,251,987,968 bytes free
***** MASTERCRC.TXT
77 File(s) 735,639,459 bytes
2 Dir(s) 68,252,004,352 bytes free
*****

if i could create the crc files with no date and time then could i delete or not compare the last two lines?

thanks again for your help if you don't know anything or don't have time i'll be fine with what I know now


Report Offensive Follow Up For Removal

Response Number 3
Name: Mechanix2Go
Date: January 12, 2007 at 15:51:35 Pacific
Subject: Simple CRC in a Batch File
Reply: (edit)

This will output size and date only:

for /f "tokens=* delims= " %%A in ('dir /a-d/od/b') do (
echo %%~zA %%~nA
)

Then you can do the FC.


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

M2



Report Offensive Follow Up For Removal

Response Number 4
Name: pball
Date: January 12, 2007 at 18:14:34 Pacific
Subject: Simple CRC in a Batch File
Reply: (edit)

Thank you very much I finally got it working like I wanted, so here is my finished script

@ECHO OFF

for /f %%i in ("%0") do set curpath=%%~dpi
cd /d %curpath%
cd /FOLDER

for /f %%A in ('dir /a-d/on/b') do (
echo %%~zA %%~nA%%~xA
) >>crc.txt

echo Wscript.Sleep 1000> sleep.vbs
start /w wscript.exe sleep.vbs

fc crc.txt mastercrc.txt > difference.txt

if errorlevel 1 goto :different

goto :join

:different
echo files don't match please send me difference.txt

goto :end

:join

::joining happens here

echo file is complete
del mastercrc.txt
del difference.txt

goto :end

:end
echo this will now close in 5 seconds

echo Wscript.Sleep 5000> sleep.vbs
start /w wscript.exe sleep.vbs
del sleep.vbs
del crc.txt

I thought I'd post it all so everyone could see what I did with everything.
Also I changed what you gave a bit so it'd give me the size. name and extension
all you have to do is run it one folder up and change FOLDER to the name of the folder then go into the folder and there should be crc.txt change it's name to mastercrc.txt and change the file size to match it again
then send files and have them run it


Report Offensive Follow Up For Removal

Response Number 5
Name: Mechanix2Go
Date: January 13, 2007 at 02:41:35 Pacific
Subject: Simple CRC in a Batch File
Reply: (edit)

That all sounds good. Glad you got it going.

A couple pointers.
If you're in the parent folder you can simply cd FOLDER. If not you can use a specific [what is it that Novell calls it? a fully qualified path] like:

cd /d d:\folder

But I would stay out of the folder and have only the files to be checked in there. I'd change this:

('dir /a-d/od/b')

to this:

('dir /a-d/od/b d:\folder')

It will avoid creating extraneous files and confusing the comparison.


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

M2



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: Simple CRC in a Batch File

Comments:

 


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




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge