I've been using DOS's DIR to locate files in a dir, and now DIR to get the path.
HOWEVER, DIR is probably not supported at all by XP, and not entirely supported in win2000.
I was thinking of doing this without the dir program somehow, but it's more convenient to just paste in the dir program......
So, my question is, where can I find the exe that allows dir? (I looked for dir.exe, doesn't exist)
Or..?
Dir is supported by W2000 AFAIK.
DIR is an internal command.com command, it is not a sepparate file.
Dir works OK in WinXP, but doesn't show long file names when called from within QB, as it did on Win9X. That can be a problem sometimes.
With "from QB" do you mean "From a DOS box"?
In W2000 dir works ok, only the undocumented /z has been substituted by the documented /x
Quote:I've been using DOS's DIR to locate files in a dir, and now DIR to get the path.
Bah, forget shelling DIR. Join the big boys and use interrupts. Faster and more reliable.
Well, I'd be great if anyone knew the 100% working and foolproof interrupt forms of the following:
Code:
SHELL "dir *.xyz > list.dir": OPEN "list.dir" FOR INPUT AS #1
LINE INPUT #1, temp$: LINE INPUT #1, temp$: LINE INPUT #1, temp$:
LINE INPUT #1, temp$
rts.dir$ = MID$(temp$, 15) + "\"
CLOSE : KILL "list.dir"
and:
Code:
SUB load.filelist (dir$)
option.amount% = 0
CHDIR dir$: SHELL "dir *.txt /b /On /L >list.dir": CLOSE
OPEN "list.dir" FOR INPUT AS #1
DO
IF EOF(1) THEN EXIT DO
option.amount% = option.amount% + 1
LINE INPUT #1, temp$
LOOP
CLOSE
OPEN "list.dir" FOR INPUT AS #1
REDIM option.list$(1 TO option.amount%)
FOR i% = 1 TO option.amount%
LINE INPUT #1, option.list$(i%)
option.list$(i%) = SHRTFN$(data.units.dir$ + option.list$(i%))
NEXT i%
CLOSE : KILL "list.dir"
END SUB
Here ags...
Code:
DEFINT A-Z
'$DYNAMIC
'$INCLUDE: 'QB.BI'
DECLARE FUNCTION DIR2$ (FileSpec$, Attr)
DECLARE FUNCTION CurrentPath$ ()
DECLARE FUNCTION FileList (Path$, Spec$, List$())
CLS
DIM List$(0)
PRINT CurrentPath$
Num = FileList(CurrentPath$, "*.*", List$())
PRINT Num; "Files"
FOR i = 1 TO Num
PRINT List$(i),
NEXT
FUNCTION CurrentPath$
DIM Regs AS RegTypeX
Regs.ax = &H1900
INTERRUPTX &H21, Regs, Regs
Drive$ = CHR$((Regs.ax AND 255) + 65)
Path$ = SPACE$(65)
Regs.ax = &H4700
Regs.dx = 0
Regs.ds = VARSEG(Path$)
Regs.si = SADD(Path$)
INTERRUPTX &H21, Regs, Regs
Path$ = LEFT$(Path$, INSTR(Path$, CHR$(0)) - 1)
IF Path$ <> "" THEN Path$ = Path$ + "\"
CurrentPath$ = Drive$ + ":\" + Path$
END FUNCTION
FUNCTION DIR2$ (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
'
' use &H10 for any directory
' use &H27 for any file
DIM DTA AS STRING * 44
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
DIR2$ = ""
EXIT FUNCTION
ELSE
RealAttr = ASC(MID$(DTA, 22, 1))
IF RealAttr AND Attr THEN
Null = INSTR(31, DTA, CHR$(0))
DIR2$ = MID$(DTA, 31, Null - 31)
EXIT FUNCTION
ELSE
FileSpecZ$ = CHR$(0)
END IF
END IF
LOOP
END FUNCTION
FUNCTION FileList (Path$, Spec$, List$())
File$ = DIR2$(Path$ + Spec$, &H27)
DO WHILE LEN(File$)
FileCount = FileCount + 1
File$ = DIR2$("", &H27)
LOOP
REDIM List$(1 TO FileCount)
File$ = DIR2$(Path$ + Spec$, &H27)
DO WHILE LEN(File$)
i = i + 1
List$(i) = File$
File$ = DIR2$("", &H27)
LOOP
FileList = FileCount
END FUNCTION
As for reliability, I've seen plenty of n00bs do a SHELL "DIR >TEMP.TXT". Now what if my current drive/directory is a CD-ROM? Oops, can't write the tempfile. Ok, use C: then. It IS possible not to have a C: drive with NT/2K/XP. Ok, use %TEMP% then. Not always defined...
has to do with the reliability of SHELL or DIR. No interrupt call is going to correct for false assumptions about hardware made by careless people. (There is no way to make carelessness reliable.) If it did, that carelessness wouldn't cause a problem when SHELL and DIR are used because DIR likely just uses that interrupt call in the first place.
command.com is different.
Thanks, Plasma, I'll try to put that in ASAP.