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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File names

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
How would it be possible to take all the file names in a directory and in any sub-directorys and stick them in a variable or variables?

This is what I have now:

REM Q$ = CHR(34)
INPUT "Where are the files located"; dir$

INPUT "How many files are there"; numfiles

FOR x = 1 TO numfiles
INPUT "File Name"; x$
PRINT #1, " File "; Q$; dir$; x$; Q$
NEXT x

I would like to be able to make this process a little more automated and only have to ask where the files are. If I stick to the method I have now, the program will have to ask for the file information again later for an uninstall loop. Which could lead to some problems if you mistype a file name.
 
You'd have to write the directory into a separate file, then open and read that file as a sequential file to do what you want with QB. PDS has the ability to read directories directly, I believe, but that feature wasn't added to the QB series. I'd make sure that this overrides any possible switches in the DIRCMD that might cause problems, too:

SHELL "dir /-p/-w/b " + dir$ " > dir.dat"

You'll have to check for subdirectories, but the /b switch will give you the file name and extension as one string so you don't have to join the name and extension.
 
With QB71 (QuickBASIC 7.1, which is part of the Professional Development Suite, or PDS, and as a result is often itself erroneously called PDS or PDS71), you can simply use the built-in DIR$() function. It is limited in that it does not allow you to specify what attributes to match, and thus can only return regular files, and not directories or any such. Also, as you will see, the way in which it is called limits you to enumerating only one set of files at a time. Even so, it is still a very useful function. The following block of code shows how it is used:
[tt]
thisFile$ = DIR$("C:\*.TXT") 'You can specify *.* for all files, and you can use a relative path
i& = 0
DO WHILE thisFile$ <> &quot;&quot;
PRINT &quot;File #&quot;; i&; &quot;: &quot;; thisFile$
thisFile$ = DIR$ 'No arguments to retrieve the next file in the current enumeration
LOOP

[/tt]
 
I don't know if I don't understand it, or it just doesn't do me any good. I'm using QBasic45, and I am pretty new if I haven't said already. Although I was able to get further than when I started this thread. I now have a new problem.

=========================================================

CLS

Q$ = CHR$(34)

INPUT &quot;Path&quot;; path$

path$ = UCASE$(path$)

SHELL &quot;dir /a-d /-p /-w /b /s &quot; + path$ + &quot; > dir.tmp&quot;

OPEN &quot;test.nsi&quot; FOR OUTPUT AS #2

OPEN &quot;dir.tmp&quot; FOR INPUT AS #1

PRINT #2, &quot;test&quot;
PRINT #2,

DO UNTIL EOF(1)
INPUT #1, tstring$

OPEN tstring$ FOR INPUT AS #3


PRINT #2, &quot; File &quot;; Q$; tstring$; Q$

CLOSE #3

LOOP

CLOSE #2
CLOSE #1

KILL &quot;dir.tmp&quot;

END

=========================================================

I want to be able to do one of two things. Ask the user where the files are located and list them that way, or run the program from in the folder and have it automatically add all the files in there. I can do the second one if I remove path$, but dir.tmp, test.nsi, and the .exe from where the program will be running, will all be added to the list. I can't have that. Since I don't know how to do the first one, right now I have mixed code and it wont run right because of path$. I'm not sure if I made any sense, but if someone can decipher what I'm trying to do, please help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top