Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Finding location of file
#1
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
y new site coming soon
Zero Productions
[Image: images\logo.jpg]
Reply
#2
Start menu?
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Reply
#3
Do you mean you want QB code to search for a file? I wrote a sub ages ago that does that; it's long-ish and complicated and scatters files across your hard disk, but deletes most of them as it goes (not if it hangs, mind! :wink: ) Want me to post?
Reply
#4
No temp files, no shelling.

Code:
' 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
Reply
#5
Plasma357...thanks...this is really useful code.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)