windows - Batch File: If file doesn't exist, create, if file does exist create a new one, compare two files, and delete the largest one -


i create batch file exports reg key folder on server, file needs perform few checks before , after.

currently have:

regedit /e "\\pdc\users\%username%\application data\printer registration.reg" "hkey_current_user\software\generic" 

the above works export registry key, batch file turned logon script, little more clever.

1: needs assess whether "printer registration.reg" exists in directory.if file not exist, must continue create file "printer registration.reg" , progress number '#2' below.

if file exists, script must export registry key file called "printer registration2.reg", , check see if file created larger 625kb. if file larger 625kb, or same size file exists "printer registration.reg", delete "printer registration2.reg".

if less 625kb , differs in file size "printer registration.reg", must delete "printer registration.reg" , rename "printer registration2.reg" "printer registration.reg".

#2: resultant file must copied users windows 7 desktop.

if me task, eternally grateful.

regards

you try this,

@echo off setlocal enabledelayedexpansion net use a: "\\pdc\users\%username%\application data\" /persistent:no >> nul set maxbytesize=625000 set file1=printer_registration.reg set file2=printer_registration2.reg  :file_check if exist "\\pdc\users\%username%\application data\printer registration.reg" (     regedit /e "\\pdc\users\%username%\application data\printer registration2.reg" "hkey_current_user\software\generic" ) else (     regedit /e "\\pdc\users\%username%\application data\printer registration.reg" "hkey_current_user\software\generic"     goto copy_final )  :check size cd a: /f "usebackq" %%a in ('%file1%') set size1=%%~za /f "usebackq" %%b in ('%file2%') set size2=%%~zb  :compare if %size2% gtr %maxbytesize% (     del "\\pdc\users\%username%\application data\printer_registration2.reg"     goto copy_final )  if %size2% equ %size1% (     del "\\pdc\users\%username%\application data\printer_registration2.reg"     goto copy_final ) else (     del "\\pdc\users\%username%\application data\printer_registration.reg"     ren "\\pdc\users\%username%\application data\printer_registration2.reg" "\\pdc\users\%username%\application data\printer_registration.reg"     goto copy_final     )  :copy_final copy "\\pdc\users\%username%\application data\printer registration.reg" %userprofile%\desktop  net use a: /delete /y 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -