Re: Verify01.exw Al
- Posted by Al Getz <Xaxo at aol.c??> Jul 19, 2007
- 692 views
don cole wrote: > > > Hello Al, > > Your code in verify01 compares a path and file with a drive letter. > I am attempting to use your code in my windows format Compare.exw. > > How can I replaced the drive letter with a path and file? I tried and I get: > > Comparing root paths: > F:\euphoria\clean\clean.exw > F:\euphoria\clean\clean.exw > > problem file: F:\euphoria\clean\clean.exwclean.exw > > Just like that. No typo here. > > I should get no errors as they are the same file. > > > Don Cole Hi Don, Here is a new Verify01.exw file. I'm going to call it Verify02.exw now. You already have all the required include files. I'll try posting it here but you'll have to watch out for line wraps so you might have to fix a few lines. If this doesnt work i'll either send you the file or upload to the archive. Take care, Al E boa sorte com sua programacao Euphoria! My bumper sticker: "I brake for LED's" From "Black Knight": "I can live with losing the good fight, but i can not live without fighting it". "Well on second thought, maybe not." [eucode] --Written by Al Getz 04/2007, updated 07/2007. --Use this when the two root directory names are different, such --as: --"C:\\download\\" and --"C:\\Euphoria\\" --The second path above can have a different drive letter too. --This compares directories and file bytes of two directories --on the same drive or different drives. --Note this reports missing files and directories in the 'B' dir --but will not report files that appear in the B dir that do not --appear in the A dir. This is mainly to compare hard drive --directories with CD drive directories after a CD write of --those directories as in a backup, or to compare two directories --on the hard drive when the second directory is a backup. --This algorithm compares bytes counts before comparing each byte --to save time when lots of files are different. It will not go --through an entire 100MB file to find out the other file has 101MB, --but will immediately report that the files are different. --To use, enter (below) RootDirNameA and the CD drive letter in DriveLetterB --and make RootPathB="", or simply enter the new entire path in RootPathB. -- Note paths on CD drive must have the same names as those -- on the hard drive, except for the drive letter, if the drive letter -- method is used. If RootPathB is used, the root directories can -- have any names. --If you are using a program launcher of any kind be sure to specify the -- working directory as well as the program path. The working directory -- will be the same directory as this exw file is located in. --Possible Report.txt error messages: -- (note the A dir is the main directory, the B dir is the backup or copy, and -- the A file resides under the A dir while the B file resides under the B dir) -- 1. "Could not find file" (the file in the A dir could not be found in the B dir) -- 2. "Bytes different in file" (A and B files have same number of bytes, but at least -- one byte is different) -- 3. "Bytes count different in file" (one file has more or less bytes than the other) -- 4. "Could not find dir" (one complete directory could not be found in the B dir) -- The following error messages can only occur if one or more files have been -- modified *AFTER* this program has been started. Of course this practice is -- not recommended. -- 5. "Could not open" (could not find the file in the directory) -- 6. "More bytes in file" (more bytes in file B than in file A) -- 7. "Not enough bytes to read in" (less bytes in file B than in file A) -- Note that a totally blank Report.txt file (after program finishes) means -- no changed files or directories have been found. --Basic program operation: --Make a list of all the directories in both root paths, then go through the A dir --directories (and files) one by one looking for directories in the B dir. Once each --dir is found, go through each file one by one comparing bytes count and if necessary --comparing each and every byte for equality. Files in the root directories are --compared also. --If any inconsistancies are found they are printed to the file "Report.txt" --that resides in the same directory as this exw file. The types of problems --that can come up are listed above (1 through 7). include misc.e include sort.e include GetDirsB.e object AllDirNamesA,AllDirNamesB integer ndirs sequence RootDirNameA,RootDirNameB,RootPathB integer DriveLetterB atom fnReport constant ReportFileName="Report.txt" --program makes a report about missing or changed files constant BackupFileListName="BackupList.txt" --program makes a backup file path list procedure printf_report(sequence formatstring, sequence info) --prints the report file and the backup list file atom fn integer n sequence name1,name2,dirnameA n=info[1] if n=1 then name1=info[2] name2=info[3] else name1=info[3] name2=info[2] end if printf(1,"\nproblem file: %s\n",{name1}) fn=open(ReportFileName,"a") printf(fn,formatstring,{name1}) close(fn) fn=open(BackupFileListName,"a") name1=info[2] name2=info[3] if length(name2)=0 then dirnameA=name1[length(RootDirNameA)+1..length(name1)] name2=RootPathB&dirnameA end if printf(fn,"%s\n",{name1}) printf(fn,"%s\n\n",{name2}) close(fn) return end procedure --//////////////////////////////////////////////////////////////////// -- USER ENTERS DATA HERE --enter root dir on drive C, and drive letter for the CD drive, --or use alternate method by entering both root dir names... --the root directory typically on the hard drive: RootDirNameA="C:\\Euphoria\\Projects\\VerifyCD\\CD1\\" --the root directory drive letter to compare (typically the CD drive letter): -- (note dirs must have same names, different drive letter when using this method) DriveLetterB='i' --make this next sequence null "" to use drive letter above alone, --or else specify the entire root path and ignore drive letter above. --This path is typically on the CD or in the backup directory... RootPathB="C:\\Euphoria\\Projects\\VerifyCD\\CD2\\" --The above example would compare RootDirNameA to RootPathB, going through all the --sub directories as well as the root directory. -- END OF USER ENTERED DATA SECTION --//////////////////////////////////////////////////////////////////// --makes sure both root paths end with a backslash: if RootDirNameA[length(RootDirNameA)]!='\\' then RootDirNameA=RootDirNameA&'\\' end if if RootPathB[length(RootPathB)]!='\\' then RootPathB=RootPathB&'\\' end if --compute the CD drive root dir: (only used with drive letter method) RootDirNameB=RootDirNameA RootDirNameB[1]=DriveLetterB --use the second path if it is not null: if length(RootPathB)>0 then RootDirNameB=RootPathB end if printf(1,"RootDirNameA: %s\n",{RootDirNameA}) printf(1,"RootDirNameB: %s\n",{RootDirNameB}) atom uDriveLetterB uDriveLetterB=upper(RootDirNameB[1]) printf(1,"Starting... %s\n",{""}) printf(1,"Comparing root paths: %s\n",{""}) printf(1," %s\n",{RootDirNameA}) printf(1," %s\n\n",{RootDirNameB}) AllDirNamesA=GetDirs(RootDirNameA) AllDirNamesB=GetDirs(RootDirNameB) ndirs=length(AllDirNamesA) printf(1,"Total number of Dirs to verify: %d\n",{ndirs}) printf(1,"See 'Report.txt' for any problem files. %s\n\n",{""}) sleep(1) fnReport=open(ReportFileName,"w") close(fnReport) fnReport=open(BackupFileListName,"w") printf(fnReport,"%s\n\n",{" Backup File List (no files here means no files"& " have changed,\n while a terminating backslash means the entire directory"& "has to be backed up):"}) close(fnReport) --look through all the dirs to see if any files are different --in bytes... sequence dirnameA,dirnameB,udirnameA,filenameA,ufilenameA,filenameB sequence FileListA,FileListB,attribs sequence uRootPathA,uRootPathB,udirnameB atom fnA,fnB,binA,binB, BytesA,BytesB integer founddir,problems,foundfile,nFiles atom t,fps,minfps uRootPathA=upper(RootDirNameA) uRootPathB=upper(RootDirNameB) problems=0 for k=1 to ndirs do printf(1,"Doing Dir Number: %d of %d\n",{k,ndirs}) founddir=0 dirnameA=AllDirNamesA[k] printf(1,"dirnameA: %s\n",{dirnameA}) udirnameA=upper(dirnameA) udirnameA=udirnameA[length(uRootPathA)+1..length(udirnameA)] for j=1 to length(AllDirNamesB) do dirnameB=AllDirNamesB[j] udirnameB=upper(dirnameB) udirnameB=udirnameB[length(uRootPathB)+1..length(udirnameB)] if equal(udirnameA,udirnameB) then --found dirname, now do files founddir=1 FileListA=dir(dirnameA) FileListB=dir(dirnameB) FileListA=sort(FileListA) FileListB=sort(FileListB) nFiles=0 t=time() minfps=1e10 for h=1 to length(FileListA) do if h/5=floor(h/5) then t=time()-t if t=0 then fps=1000 else fps=5/t end if if fps<minfps then minfps=fps end if --print: #of files done, files per second, and min files per second printf(1,"File: %d files/second: %3.2f minfps=%3.2f ",{h,fps,minfps}) puts(1,13) t=time() if h=5 then minfps=1e10 end if end if attribs=FileListA[h][2] if find('d',attribs) then --skip dir names else nFiles+=1 filenameA=FileListA[h][1] ufilenameA=upper(filenameA) foundfile=0 for i=1 to length(FileListB) do attribs=FileListB[i][2] if find('d',attribs) then --skip dir names else filenameB=FileListB[i][1] if equal(ufilenameA,upper(filenameB)) then foundfile=1 --compare bytes counts before checking all individual bytes: BytesA=FileListA[h][D_SIZE] BytesB=FileListB[i][D_SIZE] if BytesA!=BytesB then --the files are different simply because they have a different number of bytes fnA=0 fnB=0 printf_report("Bytes count different in: %s\n",{2,dirnameA&filenameA,dirnameB&filenameB}) problems+=1 exit end if --if byte count is the same then compare all byte values... fnA=open(dirnameA&filenameA,"rb") fnB=open(dirnameB&filenameB,"rb") if fnA<1 then printf_report("Could not open: %s\n",{1,dirnameA&filenameA,""}) problems+=1 exit end if if fnB<1 then printf_report("Could not open: %s\n",{2,"",dirnameB&filenameB}) problems+=1 exit end if if fnA>1 and fnB>1 then --compare file bytes while 1 do binA=getc(fnA) if binA<0 then --done comparing this file with the backup binB=getc(fnB) if binB>0 then printf_report("More bytes in file: %s\n",{2,dirnameA&filenameA,dirnameB&filenameB}) problems+=1 end if exit else binB=getc(fnB) if binB<0 then printf_report("Not enough bytes to read in: %s\n",{2,dirnameA&filenameA,dirnameB&filenameB}) problems+=1 exit else if binA=binB then --both bytes the same so continue else printf_report("Bytes different in file: %s\n",{2,dirnameA&filenameA,dirnameB&filenameB}) problems+=1 exit end if end if end if end while --1 end if --fnA and fnB if fnA>0 then close(fnA) end if if fnB>0 then close(fnB) end if end if end if end for if not foundfile then printf_report("Could not find file: %s\n",{1,dirnameA&filenameA,""}) problems+=1 end if end if end for --h printf(1,"\nFiles checked: %d\n",nFiles) exit end if end for if not founddir then printf_report("Could not find dir: %s\n",{1,dirnameA,""}) problems+=1 end if end for printf(1,"\nProblem files or directories found: %d\n",{problems}) -- print time in minutes: printf(1,"Time to complete: %8.1f minutes.\n", time()/60) printf(1,"\n%s\n",{"Close console to exit..."}) sleep(500000) --user will close out console to exit program [/eucode]