General discussion

Locked

Simple File Listing in Visual Basic

By Lab Rat ·
I am working on a project in my spare time... I have been out of VB for too long, and think someone out there can give me a hand, and help me speed up the re-learning process. :)
I need to be able to take a look at all files/folders within a certain directory on a server, and then compare that list with one taken from a local pc. How can I get a simple directory listing and transfer that data to a file, or a object type? Thanks in advance to anyone who can help me out!

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Simple File Listing in Visual Basic

by Peyison In reply to Simple File Listing in Vi ...

The following code will list the files and subdirectories in a given directory:

Sub ListFiles(asPath as String)
Dim sFile As String

'- look for normal files and subdirectories
sFile = Dir(asPath, vbNormal + vbDirectory)
Do While Len(sFile) > 0
If sFile <> "." And sFile <> ".." Then
MsgBox sFile
End If
sFile = Dir
Loop

End Sub


e.g. : ListFiles "c:\windows"

To transfer the data to a file, there are several options. You can write the file and directory names to a text file using the Print command, or you can save to a database. If the local PC has access to the directory on the server, the ListFiles routine can be called from the PC on both its directory and on the server directory and the files can be kept in arrays in memory at which point the comparison can be done - thus eliminating the need to write the files at all.

Hope this helps.

Collapse -

Simple File Listing in Visual Basic

by Lab Rat In reply to Simple File Listing in Vi ...

Poster rated this answer

Collapse -

Simple File Listing in Visual Basic

by Lab Rat In reply to Simple File Listing in Vi ...

Could you explain alittle more about the vbNormal and vbDirectory parts of the code? I still need to be able to identify what is a folder, and what is a file. How can I go about copying these files from the server to the client?

Collapse -

Simple File Listing in Visual Basic

by Lab Rat In reply to Simple File Listing in Vi ...

I think I'm on the right track. I've created a routine that checks wether it is a file or folder. Also figured out vbNormal, etc... Thx anyway. I still run into the question of copying a file/folder and preserving the long file names... Will be working on it anyhow. Will rate answers when I figure this out.

Collapse -

Simple File Listing in Visual Basic

by Lab Rat In reply to Simple File Listing in Vi ...

This question was closed by the author

Back to Web Development Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums