 |
 |

04-03-2002, 10:19 AM
|
|
Centurion
|
|
Join Date: Jun 2001
Location: CA
Posts: 150
|
|
Writing a Text File
|
Hi all, is there a way to write all of the files within a directory onto a text file using vb code? please help
ss
|
|

04-03-2002, 10:34 AM
|
 |
A+ Certified Nerd
Retired Leader * Expert *
|
|
Join Date: Dec 2001
Location: East Coast
Posts: 1,763
|
|
|
Do the filenames have consistant titles, like "File0001.txt", "File0002.txt", etc? Then you could just loop and check if the file exists. If it does, then open the file and write to it.
|
__________________
If you're not part of the solution, you're part of the precipitate.
|

04-03-2002, 10:51 AM
|
 |
Lost Soul
Super Moderator * Guru *
|
|
Join Date: May 2001
Location: Vorlon
Posts: 18,928
|
|
|
Use the Dir function to get all files in a directory (see the help for an example). Use the VB file routines (open, line input, print) to read and write the files.
|
|

04-03-2002, 11:28 AM
|
 |
Google Hound
Retired Moderator * Guru *
|
|
Join Date: Nov 2001
Location: Arizona, USA
Posts: 12,386
|
|
|
If the object is to write the contents of the files into a single file, then do as per ArnoutV; if the object is to save the file names only, then instead of opening the files, reading & copying them line by line, just write the file name to the text file.
|
__________________
Lou
"I have my standards. They may be low, but I have them!" ~ Bette Middler
"It's a book about a Spanish guy called Manual. You should read it." ~ Dilbert
"To understand recursion, you must first understand recursion." ~ unknown
|

04-03-2002, 12:14 PM
|
 |
Political Coder
Retired Moderator * Guru *
|
|
Join Date: Mar 2001
Location: London, England
Posts: 8,037
|
|
The Dir$() function can be a hard nut to crack. You start by calling it with all the parameters, to basically 'tell' it what you want it to retrieve. On all subsequent calls, you leave out the parameters and it simply repeats whatever action you did last. Your code might end up something like this:
Code:
Dim sFile As String 'Filename string variable
Dim sPath As String 'Directory string variable
sPath = "C:\"
sFile = Dir$(sPath, vbNormal) 'Look for the first file
Do Until sFile = ""
'Do stuff with the sFile here, such as:
Open sPath & sFile For Input As #1
'Read stuff from file
Close #1
Debug.Print sPath & sFile 'Print the filename to the debug window
sFile = Dir$() 'Grab next file
Loop 'Repeat until no more files remain
|
|

04-03-2002, 03:15 PM
|
|
Centurion
|
|
Join Date: Jun 2001
Location: CA
Posts: 150
|
|
|
Thank you very much everyone!!!!
|
|

04-03-2002, 07:36 PM
|
 |
Code Meister
Retired Moderator * Guru *
|
|
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
|
|
|
You could also cheat and just shell a batch file....
Shell "SaveDir.Bat"
And then write the batch file like:
Dir *.* > dir.txt
|
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
|

04-03-2002, 09:09 PM
|
|
Centurion
|
|
Join Date: Apr 2002
Location: Saratoga NY
Posts: 105
|
|
|
first go to references and make sure "microsoft scripting runtime" is selected
then add this to the general setion:
Dim fsys As New FileSystemObject
code:
dim FileNum as integer
dim thisfolder as folder
dim thisfile as file
dim thesefiles as files
set thisfolder = fsys.getfolder(<folderpath>)
set thesefiles = thisfolder.files
FileNum = FreeFile
open <Filename> for ouput as #FileNum
for each thisfile in thesefiles
write #FileNum, thisfile.name
next
close #FileNum
|
__________________
-- Nick
"oooo! they have the internet on the computer now!!" - Homer Simpson
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|