ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Finished Programs

DONE: Sync folders by renaming files

<< < (2/6) > >>

4wd:
As an aside, I think basing the rename off of file sizes is just asking for trouble since the chance of a collision does exist, however small.  On any modern computer, generating any kind of checksum for such small files wouldn't be much of a price to pay to better guard against collisions.-skwire (June 02, 2013, 04:25 PM)
--- End quote ---

V2 with MD5 checksum, requires MS File Checksum Integrity Verifier in your path somewhere:


--- Code: Text [email protected] offrem RenSS.cmdrem Rename files in dest with same size as files in sourceremrem RenSS.cmd <srce> <dest> setlocal EnableExtensionssetlocal EnableDelayedExpansion for /r %1 %%a in (*.jpg) do (call :CheckSize "%2" %%~za "%%~fa")goto End :CheckSizefor /r %1 %%b in (*.jpg) do (if %2 equ %%~zb call :CheckMD5 "%~3" "%%~b")goto :EOF :CheckMD5for /f "skip=3 delims= " %%i in ('fciv -md5 %1') do set md5_1=%%ifor /f "skip=3 delims= " %%i in ('fciv -md5 %2') do set md5_2=%%i if "!md5_1!"=="!md5_2!" (ren "%~2" "%~nx1")set md5_1=set md5_2=goto :EOF :Endendlocal
Still has built in overwrite safeguard, (ie. you can't rename to a name that already exists).

Had to find it again, the MD5 check routine came from here courtesy of James L.

V3 adds folder requesters so you can now just double-click on the cmd file :D


--- Code: Text [email protected] (@CodeSection == @Batch) @then     @echo off    setlocal EnableExtensions    setlocal EnableDelayedExpansion        for /F "delims=" %%S in ('CScript //nologo //E:JScript "%~F0"') do (        if %%S=="" exit        set srce=%%S    )    for /F "delims=" %%D in ('CScript //nologo //E:JScript "%~F0"') do (        if %%D=="" exit       set dest=%%D    )    echo Source folder: "%srce%"    echo Destination folder: "%dest%"     for /r "%srce%" %%a in (*.jpg) do (call :CheckSize "%dest%" %%~za "%%~fa"):End    set srce=    set dest=    pause    exit     :CheckSize    for /r %1 %%b in (*.jpg) do (if %2 equ %%~zb call :CheckMD5 "%~3" "%%~b")    goto :EOF     :CheckMD5    for /f "skip=3 delims= " %%i in ('fciv -md5 %1') do set md5_1=%%i    for /f "skip=3 delims= " %%i in ('fciv -md5 %2') do set md5_2=%%i     if "!md5_1!"=="!md5_2!" (ren "%~2" "%~nx1")    set md5_1=    set md5_2=    goto :EOF     endlocal     End of Batch [email protected]  // JScript section // Creates a dialog box that enables the user to select a folder and display it.var title = "Select a folder", rootFolder = 0x11;var shl = new ActiveXObject("Shell.Application");var folder = shl.BrowseForFolder(0, title, 0, rootFolder);WScript.Stdout.WriteLine(folder ? folder.self.path : "");
That particular bit of sorcery came from Antonio at DosTips.

I'm starting to wonder why I bother with AutoIt  :P

EDIT: Renamed to RenSSMD5.cmd to differentiate it from V4.

NOTE: Because of the EnableDelayedExpansion setting in V4, any filename that has an exclamation mark (!) in it will NOT be renamed.  Use V9 below if you want hash comparison and you use ! in filenames.

DyNama:
The first batch file really does work! it is very clever! i couldn't have written it. a little low tech tho. perhaps i lied about the "whatever is easier".  :D

I'm an old DOS man, but i eventually forgot most of the DOS i knew when i reluctantly converted to Windows in 1995. i don't actually know how to set my path any more, so i put fciv in the same folder RenSSv3 is in. i neglected to say i'm running this on a win7 x64 Dell laptop with several external hard drives.

It's good to have a checksum option, but i just checked a couple hundred .jpgs and videos and couldn't find a single pair of files that were exactly the same size, even pix taken within seconds of each other. i do have lots of videos too, and i'm afraid checksums would take a long time. before i asked this question, i tried a few sync programs and dupe finders; FreeFileSync when given 2 dozen videos on each side to examine estimated it would take 2 hours. can it check the date and time instead of checksum?
 

4wd:
It's good to have a checksum option, but i just checked a couple hundred .jpgs and videos and couldn't find a single pair of files that were exactly the same size, even pix taken within seconds of each other.-DyNama (June 03, 2013, 02:35 AM)
--- End quote ---

I didn't think it would work to well due to the EXIF data contained within the JPG possibly being different even though the image data and size might be identical.

i do have lots of videos too, and i'm afraid checksums would take a long time. before i asked this question, i tried a few sync programs and dupe finders; FreeFileSync when given 2 dozen videos on each side to examine estimated it would take 2 hours. can it check the date and time instead of checksum?
--- End quote ---

Should be doable, so you want size, date and time to be matched ?

DyNama:
i tried RenSSv1 (filesize only) on 2 folders with 16 ~320meg videos each and it worked just fine once i changed the file to ".avi", then ".wmv", then ".mp4". there's a way to pass the extension to the batch file too, isn't there?

then i tried RenSSv3 on a folder with 110 videos = 29.6gigs, and it's backup, of which only about a dozen files actually needed renaming. 22 .mp4s = 8gigs took about 15 minutes. 75 .wmvs = 16.8gigs took about 25minutes. does the program detect whether the file needs renaming? i much prefer selecting folders from a list rather than typing at a command prompt―thanx!

some files that should have been did not get renamed. also i get a DOS error message: The system cannot find the file specified. on one run i got it 9 times before it was done. most if not all of the new file names had punctuation marks in them, especially exclamation points, for example [email protected] is there anything in the process that would balk at that?

Thanx for the help!

4wd:
there's a way to pass the extension to the batch file too, isn't there?-DyNama (June 03, 2013, 03:14 AM)
--- End quote ---

No, but who knows, there may be a way to hack it in.

then i tried RenSSv3 on a folder with 110 videos = 29.6gigs, and it's backup, of which only about a dozen files actually needed renaming. 22 .mp4s = 8gigs took about 15 minutes. 75 .wmvs = 16.8gigs took about 25minutes. does the program detect whether the file needs renaming?
--- End quote ---

It checks the size, if they are the same then it generates an MD5 checksum for each file, if they are the same it will rename one.  Generating MD5 checksums take time on large files.

is there anything in the process that would balk at that?
--- End quote ---

It uses the standard DOS rename command, so if it can't handle it then it will fail.  However, maybe I forgot something, I'll check.

V4 RenSSDT.cmd - matches size, date and time and asks for an extension.


--- Code: Text [email protected] (@CodeSection == @Batch) @then     @echo off    setlocal EnableExtensions    setlocal DisableDelayedExpansion        for /F "delims=" %%S in ('CScript //nologo //E:JScript "%~F0"') do (        if %%S=="" exit        set srce=%%S    )    for /F "delims=" %%D in ('CScript //nologo //E:JScript "%~F0"') do (        if %%D=="" exit       set dest=%%D    )    echo Source folder: "%srce%"    echo Destination folder: "%dest%"    set /P ext=Please enter extension [eg. jpg]:     if %ext%=="" exit        for /r "%srce%" %%a in (*.%ext%) do (call :CheckSize "%dest%" %%~za "%%~fa"):End    set srce=    set dest=    set ext=    pause    exit     :CheckSize    for /r %1 %%b in (*.%ext%) do (if %2 equ %%~zb call :CheckDate "%~3" "%%~b")    goto :EOF     :CheckDate    if "%~t1" equ "%~t2" (        pushd "%~dp1"        ren "%~nx2" "%~nx1"    )    popd    goto :EOF        endlocal     End of Batch [email protected]  // JScript section // Creates a dialog box that enables the user to select a folder and display it.var title = "Select a folder", rootFolder = 0x11;var shl = new ActiveXObject("Shell.Application");var folder = shl.BrowseForFolder(0, title, 0, rootFolder);WScript.Stdout.WriteLine(folder ? folder.self.path : "");
It seems to handle files with ! in the name now, (! doesn't get passed if Delayed Expansion is enabled).

BTW, I hope you're trying these out on copies of your files before you let it run for real over your real files.  As I said, it works for me with the limited testing I do but then my machine is not your machine.

EDIT: I just realised after doing all these different versions that I think I've got the source and destination around the wrong way - won't change it now, it'll only be confusing, (as if I aren't already).  FIXED!

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version