Wednesday, July 25, 2012

Windows recursive copy and cksum


Option 1  [Recommended – as it gives output in a consistent format of cksum, filesize, filename without path]
USING rcopy to copy all files into a single directory and then cksum
  1. Open notepad and copy-paste the below rcopy part into it.
  2. Save file as “rcopy_cmd.cmd”
  3. To copy all files to a single directory, execute the following command:  rcopy_cmd.cmd [SVN_LATEST_FILE_PATH_ON_LOCAL_MACHINE]
  4. Finally, run the command from “D:\TESTCOPY” directory: [CKSUM.EXE_PATH]\cksum.exe * > cksum_off.txt
  5. Zip the cksum_off.txt and email it.

       Note:  
         cksum.exe can be from http://gnuwin32.sourceforge.net/packages/coreutils.htm
         Do not forget the dependencies (libintl3.dll, libiconv2.dll) available on same site.


      Standalone recursive copy command execution

rcopy
==START==
@REM  Batch file to recursively get copy files to "D:\TESTCOPY" in Windows
@REM  Usage: rcopy_cmd.cmd [DIR]


@echo off

echo START: %date% %time%

@REM  Go to input DIR
pushd "%1"

@REM  For every file in current dir do (...) [/r = Recursively for every directory]
for /r %%f in (*) do (
  copy "%%f" "D:\TESTCOPY"
  )

@REM  Get back to present working directory
popd

echo END: %date% %time%

@echo on
==END==



cksum.exe "D:\TESTCOPY" > cksum_out.txt


Option 2

      Standalone recursive cksum command execution

cksum_cmd
==START==
@REM  Batch file to recursively get cksum in Windows
@REM  Usage: cksum_cmd.cmd [DIR] > cksum_out.txt


@echo off

echo START: %date% %time%

@REM  Go to input DIR
pushd "%1"

@REM  For every file in current dir do (...) [/r = Recursively for every directory]
for /r %%f in (*) do (
  D:\work\bin\cksum.exe "%%f"
  )

@REM  Get back to present working directory
popd

echo END: %date% %time%

@echo on
==END==


EXTRA

Process to copy all files stated in one list file to one directory.

@REM Create the directory to which the files are to be copied to
mkdir D:\TESTCPY2

@REM Assuming all files are present in one directory called “All_Files”
@REM Read one line at a time from the list file
for /F "tokens=*" %L in (list_of_files.txt) do (
  copy All_Files\%L D:\TESTCPY2
)

Note:  To use the above command in a batch file, change %L to %%L
 

No comments: