 |
 |

03-31-2003, 04:06 PM
|
|
|
files in folder
|
How do I get all the file names in a folder?
I need to create an outbox folder and get all the files inside that folder to further processing.
thanks
another quick question, what function do I use to move a FileName from a folder to another one
thanks
|
|

03-31-2003, 04:39 PM
|
|
Centurion
|
|
Join Date: Dec 2002
Posts: 124
|
|
Try something like this:
Code:
Private Sub Command1_Click()
Dim Files As String
Files = Dir("c:\")
While Files <> ""
If Files <> "" Then
MsgBox Files
Files = Dir
End If
Wend
End Sub
Use FileCopy to move/copy a file to another folder, then delete it (Kill) from the current folder if you need to.
|
|

03-31-2003, 04:44 PM
|
|
Promising Talent
Retired Moderator * Guru *
|
|
Join Date: May 2002
Location: Brussels
Posts: 3,601
|
|
|
You can also use the Name statement to move a file, that way you don't need to use Kill.
|
|

03-31-2003, 05:04 PM
|
 |
Junior Contributor
|
|
Join Date: May 2002
Location: Rural Northwest USA
Posts: 315
|
|
Was going to post a quick reply, but got bogged down experimenting. This function uses Dir() to fill an array with filenames. It's clumsy, but you get the idea:
Code:
Function GetAllFilesInFolder(strPathToFolder As String, _
strFileNamesArray() As String) As Boolean
On Error GoTo Whoops
Dim x As Integer, y As Integer, strFileName As String
ReDim strFileNamesArray(0 To 99)
strFileNamesArray(0) = Dir(strPathToFolder)
x = 1
strFileName = Dir
Do While strFileName <> ""
If strFileName <> "" Then
strFileNamesArray(x) = strFileName
x = x + 1
strFileName = Dir
Else: Exit Do
End If
Loop
ReDim Preserve strFileNamesArray(0 To x)
GetAllFilesInFolder = True
For y = 0 To x 'strip this out once you get it working
Debug.Print strFileNamesArray(y)
Next
OffRamp:
Exit Function
Whoops:
GetAllFilesInFolder = False
End Function
You need to Dim a string array in the code that calls this, and use it for the 2nd argument.
|
|

03-31-2003, 05:04 PM
|
|
|
|
Thanks a lot dgdolins1, that routine worked as expected.
Deadalus, how do I use the Name statement?
What I plan to do is take the files from an 'outbox' folder and place all those files in a 'sent' folder
I thought about using the FileCopy and Kill functions as suggested by dgdolins, but if there is a more efficient way of doing it the better.
Thanks guys
|
|

03-31-2003, 05:11 PM
|
 |
Google Hound
Retired Moderator * Guru *
|
|
Join Date: Nov 2001
Location: Arizona, USA
Posts: 12,378
|
|
|
Name Oldname as Newname
I don't believe it works across drive boundries, though.
|
__________________
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
|

03-31-2003, 06:02 PM
|
|
Promising Talent
Retired Moderator * Guru *
|
|
Join Date: May 2002
Location: Brussels
Posts: 3,601
|
|
I've heard that before about the Name statement, but MSDN says this about it
Quote:
|
Name can move a file across drives, but it can only rename an existing directory or folder when both newpathname and oldpathname are located on the same drive. Name cannot create a new file, directory, or folder.
|
In this part of strBean's code
Code:
Do While strFileName <> ""
If strFileName <> "" Then
strFileNamesArray(x) = strFileName
x = x + 1
strFileName = Dir
Else: Exit Do
End If
Loop
only this is functional:
Code:
Do While strFileName <> ""
strFileNamesArray(x) = strFileName
x = x + 1
strFileName = Dir
Loop
The if condition was just repeating the While condition. Also, the label OffRamp doesn't seem to be used and you might want to add code in the loop to redimension the array when x reaches the ubound of the array (over 100 files).
|
|

03-31-2003, 06:07 PM
|
 |
Junior Contributor
|
|
Join Date: May 2002
Location: Rural Northwest USA
Posts: 315
|
|
Quote: Originally Posted by Deadalus
only this is functional:
Code:
Do While strFileName <> ""
strFileNamesArray(x) = strFileName
x = x + 1
strFileName = Dir
Loop
I know, I saw that. And I saw where the ubound could be a problem. But you guys are so fast I had to hurry up and post.
|
|

03-31-2003, 06:26 PM
|
|
Promising Talent
Retired Moderator * Guru *
|
|
Join Date: May 2002
Location: Brussels
Posts: 3,601
|
|
Hey, it's not a race. In the end things get solved quicker (and you learn more) if you take your time to test and review the code. Plus you get to correct hurried posters. 
|
|

04-01-2003, 06:36 AM
|
|
|
|
Thanks guys, this forum is the best!
|
|
|
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
|
|
|
|
|
|
|
|
 |
|