03-01-2003, 11:27 AM
I know this sounds stupid but i want this to work on XP so is there any command of pecie of code that will find the location of a file Im talking about when it is ex. C:\qb\game\game.exe
thx
thx
' File Searching by Plasma357
DEFINT A-Z
'$INCLUDE: 'QB.BI'
DECLARE FUNCTION DIR$ (FileSpec$, Attr)
DECLARE FUNCTION FindFile$ (File$, StartPath$)
DECLARE FUNCTION GetPath$ (Filename$)
DIM SHARED DTA AS STRING * 44
DIM Regs AS RegType
CLS
INPUT "Enter the filename to search for: ", Filename$
PRINT
PRINT
PRINT "Please wait, searching for " + Filename$ + "... (press ESC to cancel search)"
PRINT
FOR Drive = 1 TO 26
Regs.ax = &H4408
Regs.bx = Drive
INTERRUPT &H21, Regs, Regs
IF Regs.ax = 1 AND NOT Regs.flags AND 1 THEN
Drive$ = CHR$(Drive + 64)
Result$ = FindFile$(Filename$, Drive$ + ":\")
IF Result$ <> "" THEN
EXIT FOR
END IF
END IF
NEXT
LOCATE , 1
PRINT SPACE$(80);
LOCATE , 1
IF Result$ = " " THEN
PRINT "Search cancelled!"
ELSEIF Result$ = "" THEN
PRINT "File not found!"
ELSE
PRINT "File found!"
PRINT
PRINT "Full filename: " + Result$
PRINT " Path: " + GetPath$(Result$)
END IF
FUNCTION DIR$ (FileSpec$, Attr) STATIC
'Settings for Attr: (may be combined)
'
' &H40 Device
' &H20 Archive
' &H10 Directory
' &H8 Volume Label
' &H4 System File
' &H2 Hidden File
' &H1 Read-Only File
FileSpecZ$ = FileSpec$ + CHR$(0)
DO
DIM Regs AS RegTypeX
Regs.ax = &H1A00
Regs.ds = VARSEG(DTA)
Regs.dx = VARPTR(DTA)
InterruptX &H21, Regs, Regs
IF FileSpecZ$ <> CHR$(0) THEN
Regs.ax = &H4E00
Regs.cx = Attr
Regs.ds = VARSEG(FileSpecZ$)
Regs.dx = SADD(FileSpecZ$)
ELSE
Regs.ax = &H4F00
END IF
InterruptX &H21, Regs, Regs
IF Regs.flags AND 1 THEN
DIR$ = ""
EXIT FUNCTION
ELSE
RealAttr = ASC(MID$(DTA, 22, 1))
IF RealAttr AND Attr THEN
Null = INSTR(31, DTA, CHR$(0))
DIR$ = MID$(DTA, 31, Null - 31)
EXIT FUNCTION
ELSE
FileSpecZ$ = CHR$(0)
END IF
END IF
LOOP
END FUNCTION
FUNCTION FindFile$ (File$, StartPath$)
DIM SaveDTA AS STRING * 44
LOCATE , 1
PRINT StartPath$ + SPACE$(80 - LEN(StartPath$));
Key$ = INKEY$
IF Key$ = CHR$(27) THEN
FindFile$ = " "
EXIT FUNCTION
END IF
'look for the file in this dir first
FoundFile$ = DIR$(StartPath$ + File$, &H27)
IF LEN(FoundFile$) THEN
FindFile$ = StartPath$ + FoundFile$
EXIT FUNCTION
END IF
'not in this dir, so get a list of dirs in this dir and recurse them
FoundDir$ = DIR$(StartPath$ + "*.*", &H10)
DO WHILE FoundDir$ <> ""
IF FoundDir$ <> "." AND FoundDir$ <> ".." THEN
SaveDTA = DTA
Recurse$ = FindFile$(File$, StartPath$ + FoundDir$ + "\")
DTA = SaveDTA
IF Recurse$ <> "" THEN
FindFile$ = Recurse$
EXIT FUNCTION
END IF
END IF
FoundDir$ = DIR$("", &H10)
LOOP
FindFile$ = ""
END FUNCTION
FUNCTION GetPath$ (Filename$)
FOR x = LEN(Filename$) TO 1 STEP -1
IF MID$(Filename$, x, 1) = "\" THEN
GetPath$ = LEFT$(Filename$, x)
EXIT FOR
END IF
NEXT
END FUNCTION