|
-
Nov 17th, 2008, 02:29 PM
#1
Thread Starter
Fanatic Member
read files in folder and asign file names into an array
how would i read inside a directory, all the files. i want to take the names of the files and assign them to a string array.
also the user is going to be choosing a folder. so how can they choose the folder they want? like i need almost like a file save as thing, where you choose your location, but they are picking a folder.
-JOe
Software languages known:
Qbasic - TI-Basic - Liberty Basic - Visual Basic 6
Software API's known:
Directx 7 and 8
Internet languages, in the process of learning:
HTML - JAVASCRIPT - PHP - CSS - MYSQL - AJAX
-
Nov 17th, 2008, 03:07 PM
#2
Re: read files in folder and asign file names into an array
Joe, the easiest way to get the files/folders within a selected folder:
Code:
Dim sFile As String
sFile = Dir$([selectedFolderPath] & "\*.*", vbDirectory Or vbHidden Or vbSystem Or vbReadOnly or vbArchive)
Do Until sFile = vbNullString
If sFile <> "." Then ' relative path meaning this directory
If sFile <> ".." Then ' relative path meaning parent directory
' add the file to your array here
End If
End If
sFile = Dir$()
Loop
Recommend doing a quick search for "Browse for Folder". The code will be in a module or class, since VB has no control to do that functionality. The window displayed is folder based only, no files (though it can be set up that way), and something I'm sure you have seen before.
Last edited by LaVolpe; Nov 17th, 2008 at 03:26 PM.
-
Nov 17th, 2008, 03:12 PM
#3
Thread Starter
Fanatic Member
Re: read files in folder and asign file names into an array
how can the user choose the folder? oh... i just looked maybe that was the last part of your post...
i need to get folder names inside that main folder and name them as strings too... how to do that?
then i need to open those folders and name those files in that folder to strings, and thats all i need.. any other help?
Software languages known:
Qbasic - TI-Basic - Liberty Basic - Visual Basic 6
Software API's known:
Directx 7 and 8
Internet languages, in the process of learning:
HTML - JAVASCRIPT - PHP - CSS - MYSQL - AJAX
-
Nov 17th, 2008, 03:13 PM
#4
Re: read files in folder and asign file names into an array
 Originally Posted by damasterjo
how can the user choose the folder?
As I suggested:
 Originally Posted by LaVolpe
Recommend doing a quick search for "Browse for Folder". The code will be in a module or class, since VB has no control to do that functionality. The window displayed is folder based only, no files (though it can be set up that way), and something I'm sure you have seen before.
Once you have the folder to start in, are you saying you need to do a recursive search through all subfolders, all their subfolders, on an on?
Edited: Do you need file names or folder names? If both, then the code I posted above will work. If just file names or just folder names, it needs to be tweaked a little bit.
Last edited by LaVolpe; Nov 17th, 2008 at 03:17 PM.
-
Nov 17th, 2008, 03:24 PM
#5
Thread Starter
Fanatic Member
Re: read files in folder and asign file names into an array
*main folder*
file
file
file
up to 5 *subfolders* in main folder
file
file
file
i need all files main folder and subfolders to be strings...
is there anyway you could break down that code just a little more? right now i dont have vb6 i cant get it till tomorrow, i need to have this ready by then sorta
EDIT: so basically im sure i can figure your code out when i can compile it and display the results and see what i see, but if you can explain alittle more i would really really apreciate it..
EDIT 2: and i dont understand the "." and ".."
Software languages known:
Qbasic - TI-Basic - Liberty Basic - Visual Basic 6
Software API's known:
Directx 7 and 8
Internet languages, in the process of learning:
HTML - JAVASCRIPT - PHP - CSS - MYSQL - AJAX
-
Nov 17th, 2008, 03:29 PM
#6
Re: read files in folder and asign file names into an array
Yes the code in post#2, should give you everything but the main folder. The main folder is the "selectedFolderPath" in that code, so you will already know its name.
Keep this in mind, the results will be just the names, not the full path. The full path will be the main folder's path + the file/subfolder names
-
Nov 17th, 2008, 03:30 PM
#7
Thread Starter
Fanatic Member
Re: read files in folder and asign file names into an array
what order are these files coming in?
Software languages known:
Qbasic - TI-Basic - Liberty Basic - Visual Basic 6
Software API's known:
Directx 7 and 8
Internet languages, in the process of learning:
HTML - JAVASCRIPT - PHP - CSS - MYSQL - AJAX
-
Nov 17th, 2008, 03:36 PM
#8
Thread Starter
Fanatic Member
Re: read files in folder and asign file names into an array
why are there 2 if statements?
Software languages known:
Qbasic - TI-Basic - Liberty Basic - Visual Basic 6
Software API's known:
Directx 7 and 8
Internet languages, in the process of learning:
HTML - JAVASCRIPT - PHP - CSS - MYSQL - AJAX
-
Nov 17th, 2008, 03:39 PM
#9
Re: read files in folder and asign file names into an array
Whatever order VB gives them to you, usually alphabetical.
To determine if a name is a folder or file, the code modified a little...
Code:
Dim sFile As String
Dim sDir As String
sDir = "C:\Program Files\" ' make sure backslash is included
sFile = Dir$(sDir & "*.*", vbArchive Or vbHidden Or vbReadOnly Or vbSystem Or vbDirectory)
Do Until sFile = vbNullString
If sFile <> "." Then ' relative path meaning this directory
If sFile <> ".." Then ' relative path meaning parent directory
If (GetAttr(sDir & sFile) And vbDirectory) Then
Debug.Print "Folder: "; sFile
Else
Debug.Print " File: "; sFile
End If
End If
End If
sFile = Dir$()
Loop
 Originally Posted by damasterjo
why are there 2 if statements?
I explained in the comments within the code. Remove them and you will get folder names of ".." & "."
-
Nov 17th, 2008, 03:43 PM
#10
Thread Starter
Fanatic Member
Re: read files in folder and asign file names into an array
ok thanks, looks like that will be great for now, i will be testing my uses tomorrow, if i need anymore info i will ask, thanks
Software languages known:
Qbasic - TI-Basic - Liberty Basic - Visual Basic 6
Software API's known:
Directx 7 and 8
Internet languages, in the process of learning:
HTML - JAVASCRIPT - PHP - CSS - MYSQL - AJAX
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|