TIP: Click on subject to list as thread! ANSI
echo: power_bas
to: ALL
from: BRIAN MCLAUGHLIN
date: 1995-04-25 21:19:00
subject: A FREE UTILITY PROGR 1/2

For the heck of it, here is some code. Some of you may have seen it
before. It is a simple utility that combs through every file on the
C: drive and reports which filenames are duplicated in which
directories.
For the sake of simplicity, it reports by creating a file named
DUPEFILE.LST and putting it in the root directory of C:. It does
this because the root can always be counted on to exist.
As usual, you could add a bunch of bells and whistles to this. Feel
free.
'=================================================================
' LISTDUPE.BAS  by Brian McLaughlin, compile with PowerBASIC 3.x
'
' Searches C: drive for duplicate files and creates a file listing
' those duplicates, in the root dir of C: drive, named DUPEFILE.LST.
'=================================================================
$CPU 80386             'make it faster
$LIB ALL OFF           'make it smaller
$FLOAT PROCEDURE       'if you have a co-pro, use NPX instead
DECLARE SUB GatherNames (DirNames$(), File$(), FileDir%())
DECLARE SUB MakeDupeList (DirNames$(), File$(), FileDir%())
DECLARE SUB PrintTwirlBar (Counter%)
Synch! = TIMER: DO: Start! = TIMER: LOOP UNTIL Start! > Synch!
  DIM DirName$(1 TO 1400)    'handles up to 1400 directories
  DIM FileName$(1 TO 16384)  'handles up to 16K file names
  DIM FileDir%(1 TO 16384)   'indexes file names to dir names
  SHARED gFileTotal%         'a global variable used in both SUBs
  GatherNames DirName$(), FileName$(), FileDir%()
  MakeDupeList DirName$(), FileName$(), FileDir%()
Elapsed! = TIMER - Start!: PRINT: PRINT "Elapsed time:"; Elapsed!
PRINT: PRINT "To find the file DUPEFILE.LST, look in root directory."
END
'==================================================
 SUB GatherNames (DirName$(), File$(), FileDir%())  STATIC
'==================================================
 AllSpec$ = "*.*"
 Slash$ = "\"
 DirAttrib% = &H10
 AllAttrib% = &H10 OR &H2 OR &H4  'attrib for dirs, system and hidden files
 gFileTotal% = 0
 DirTotal% = 1
 DirIndex% = 1
 DirName$(1) = "C:\"              'to search current drive, just use "\"
 PRINT "Collecting filenames... ";         'give 'em something to look at
 DO                                        'directory-switching loop
   ThisDir$ = DirName$(DirIndex%)          'search next dir
   PrintTwirlBar DirIndex%
   FileSpec$ = ThisDir$ + AllSpec$         'look for *.* in that dir
   ThisName$ = DIR$(FileSpec$, AllAttrib%) 'includes subdirs, hidden, system
   IF LEN(ThisName$) THEN
     IF (ATTRIB(ThisDir$ + ThisName$) AND DirAttrib%) THEN
        INCR DirTotal%
        DirName$(DirTotal%) = ThisDir$ + ThisName$ + Slash$
     ELSE
        INCR gFileTotal%
        File$(gFileTotal%) = ThisName$
        FileDir%(gFileTotal%) = DirIndex%
     END IF
     DO                          'main directory-searching loop
        ThisName$ = DIR$
        IF LEN(ThisName$) THEN
           IF (ATTRIB(ThisDir$ + ThisName$) AND DirAttrib%) THEN
              INCR DirTotal%
              DirName$(DirTotal%) = ThisDir$ + ThisName$ + Slash$
           ELSE
              INCR gFileTotal%
              File$(gFileTotal%) = ThisName$     'saves name of file
              FileDir%(gFileTotal%) = DirIndex%  'index to pathname
           END IF
        ELSE
           EXIT DO     'if null name, then exit loop
        END IF
     LOOP
   END IF
   INCR DirIndex%
 LOOP UNTIL DirIndex% > DirTotal%
END SUB
'==================================================
 SUB MakeDupeList (DirName$(), File$(), FileDir%())  STATIC
'==================================================
 CRLF$ = CHR$(13,10)
 Indent$ = "  "
 Found$ = " was found in:" + CRLF$ + Indent$
 Header$ = "Total duplicate files found on C: drive:"
 Spacer$ = "      "           'saves room for number of dupes
 Accum$ = Header$ + Spacer$ + CRLF$ + CRLF$
 PRINT: PRINT "Sorting files..."
 ARRAY SORT File$(1) FOR gFileTotal%, TAGARRAY FileDir%()
 OutFile$ = "C:\DUPEFILE.LST"
 BakFile$ = "C:\DUPEFILE.BAK"
 IF LEN(DIR$(BakFile$)) THEN KILL BakFile$
 IF LEN(DIR$(OutFile$)) THEN NAME OutFile$ AS BakFile$
 OPEN OutFile$ FOR BINARY AS #1
 Dupes% = 0
 ThisFile% = 1
 FileOne$ = File$(ThisFile%)
 PRINT "Collecting duplicates... ";
 DO
    LastNonDupe% = ThisFile%      'assume this file isn't a dupe
    DO
      INCR ThisFile%              'look at the next adjacent file
      PrintTwirlBar ThisFile%     'give the user something to stare at
      FileTwo$ = File$(ThisFile%)
      IF LEN(FileOne$) = LEN(FileTwo$) THEN  'eliminates some files quickly
         IF FileOne$ = FileTwo$ THEN         'if equal, we found a dupe
            LastDupe% = ThisFile%
            ThisDirNum% = FileDir%(ThisFile%)
            Dir2$ = DirName$(ThisDirNum%) + CRLF$
            IF LastNonDupe% = (ThisFile% - 1) THEN
               PrevDirNum% = FileDir%(LastNonDupe%)
               Dir1$ = DirName$(PrevDirNum%) + CRLF$
               Accum$ = Accum$ + FileOne$ + Found$ + Dir1$ + Indent$ + Dir2$
               INCR Dupes%, 2            'count both this and previous file
            ELSE
               Accum$ = Accum$ + Indent$ + Dir2$
               INCR Dupes%
            END IF
>>> Continued to next message
 * SLMR 2.1a * MAXLIB For PB v1.1 - Access arrays and files in EMS/XMS!
--- WILDMAIL!/WC v4.12 
---------------
* Origin: Com-Dat BBS - Hillsboro, OR. HST DS (1:105/314.0)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.