Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Files Command

Status
Not open for further replies.

fancom

Programmer
Feb 7, 2001
46
TR
Is there a way to get the names of files and directories into an array listed by the command Files ?
 
I think there is a hack, but I can't remember off the top of my head...

for a quick workaround... 'pipe' the output to a text file...

Normal Use:
Dir *.txt

Pipe to 'C:\MyTmpDir.tmp' use:
Dir *.txt<C:\MyTmpDir.tmp

To use this in QB...
Code:
  Shell &quot;Dir &quot; + Path$ + &quot;*.txt<C:\MyTmpDir.tmp&quot;
  ArraySize = 0
  Open &quot;C:\MyTmpDir.tmp&quot; for Output As #1
    Do
      Line Input #1, A$
      ArraySize = ArraySize + 1
    Loop Until EOF(1)
  Close
  Redim MyArray$(ArraySize)
  Open &quot;C:\MyTmpDir.tmp&quot; for Output As #1
    For N = 1 to ArraySize
      Line Input #1, MyArray$(N)
    Next
  Close


Have Fun, Be Young... Code BASIC
-Josh
cubee101.gif

 
CubeE101,
I'm afraid to pipe output you should use &quot;>&quot; instead...
Ok,I tried that program in QBasic - one more thing: one need open for Input.
So, it goes like this:

Code:
   path$ = &quot;c:\&quot;
   SHELL &quot;Dir &quot; + path$ + &quot;*.txt /b>C:\MyTmpDir.tmp&quot;
   ASize = 0
   OPEN &quot;C:\MyTmpDir.tmp&quot; FOR INPUT AS #1
   DO
   LINE INPUT #1, A$
      ArraySize = ArraySize + 1
   LOOP UNTIL EOF(1)
   CLOSE
   REDIM MyArray$(ArraySize)
   OPEN &quot;C:\MyTmpDir.tmp&quot; FOR INPUT AS #1
   FOR N = 1 TO ArraySize
      LINE INPUT #1, MyArray$(N)
   NEXT
   CLOSE
   PRINT &quot;Directory for &quot;; path$; &quot; (*.txt)&quot;
   PRINT &quot;Number of files: &quot;; ArraySize
   FOR N = 1 TO ArraySize
      PRINT MyArray$(N)
   NEXT
 
That's right...

< pipes the text into the program...

> pipes the text to a file...

Thanks, i used to always use a program where you had to use the < pipe, so my mind associates pipe with <...

Sorry for the typo on the input also, thanks for the corrections

(I think I must have been Output Dyslexically Challenged (ODC) yesterday;-))


Have Fun, Be Young... Code BASIC
-Josh
cubee101.gif

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top