Qbasicnews.com
February 27, 2020, 09:02:42 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1] 2 3
  Print  
Author Topic: dir command >> exe?  (Read 8107 times)
Agamemnus
x/ \z
*****
Posts: 3491



« on: July 15, 2003, 12:13:15 PM »

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..?
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Antoni Gual
Na_th_an
*****
Posts: 1434



WWW
« Reply #1 on: July 15, 2003, 12:22:07 PM »

Dir is supported by W2000 AFAIK.
DIR is an internal command.com command, it is not a sepparate file.
Logged

Antoni
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #2 on: July 15, 2003, 12:30:29 PM »

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.
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Antoni Gual
Na_th_an
*****
Posts: 1434



WWW
« Reply #3 on: July 15, 2003, 01:24:10 PM »

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
Logged

Antoni
Plasma
Na_th_an
*****
Posts: 1770


WWW
« Reply #4 on: July 15, 2003, 01:26:47 PM »

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.
Logged
Glenn
I hold this place together
*****
Posts: 786



WWW
« Reply #5 on: July 15, 2003, 01:30:48 PM »

.
Logged

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.
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #6 on: July 15, 2003, 01:32:29 PM »

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
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Plasma
Na_th_an
*****
Posts: 1770


WWW
« Reply #7 on: July 15, 2003, 02:46:25 PM »

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...
Logged
Glenn
I hold this place together
*****
Posts: 786



WWW
« Reply #8 on: July 15, 2003, 03:05:18 PM »

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.
Logged

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.
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #9 on: July 15, 2003, 03:10:51 PM »

command.com is different.

Thanks, Plasma, I'll try to put that in ASAP.
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Glenn
I hold this place together
*****
Posts: 786



WWW
« Reply #10 on: July 15, 2003, 03:35:08 PM »

If you think INT 21 isn't fundamentally important to how command.com operates, well, as usual, you're confused again.  Smiley
Logged

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.
Agamemnus
x/ \z
*****
Posts: 3491



« Reply #11 on: July 15, 2003, 03:40:03 PM »

What I meant is:

command.com is different across windoze versions, and in some cases may not exist.

EDIT: I patched up your routine a bit, Plasma, and got it to work with the program. Smiley
Logged

Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Plasma
Na_th_an
*****
Posts: 1770


WWW
« Reply #12 on: July 15, 2003, 03:42:25 PM »

I never said there was anything wrong with SHELL or DIR. I did point out that the common solution of SHELL "DIR >somefile.txt" is not reliable, due to the fact that a temporary file has to be created, and the current directory is not always writeable. Most people who use this method do not assure that this temporary file can be created, they just assume it can be.

I'm not a freaking moron, I know how DIR works. Tongue
Logged
Glenn
I hold this place together
*****
Posts: 786



WWW
« Reply #13 on: July 15, 2003, 04:14:44 PM »

But as I said, that doesn't relate to the reliability of using SHELL and DIR.  It relates to the reliability of careless assumptions (which is an oxymoron).  There is no need to assume that the current directory resides on a disk that is writable or to write the file to the current directory.  People trying to program who don't even know what disks they have that are writable shouldn't be trying.  (I have a few more years experience than you catering to people trying to use computers who don't have the basic qualifications to be trying in the first place.  It's not as easy or painless as you make it sound.  Smiley  )

(And I never said  that you did say it was wrong to use SHELL and DIR.  I never, for the record, said it was wrong to just use the interrupt call directly either.  Smiley  )

And Agamemnus, I've never used any version of windows that didn't at least provide a command.com for DOS programs to work.  If you're using such an implementation/installation, what are you doing trying to run DOS programs with it?  (And the differences between different command.com's are irrelevant in regard to this context.  If anything, DIR works *better* with the newer versions of windows.)
Logged

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.
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #14 on: July 15, 2003, 04:20:29 PM »

Quote from: "Antoni Gual"
With "from QB" do you mean "From a DOS box"?


Nope. I mean from QB. The command

Code:
shell "dir"


will show short filenames (~n stuff)

dir typed directly in a DOS box works correctly
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Pages: [1] 2 3
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!