|
-
Oct 2nd, 2002, 11:28 AM
#1
Thread Starter
Hyperactive Member
filesystemobject help!
hello,
i'm just starting to write a program that will look through a folder containing other folders (all on one level)
inside these folders are lots of jpgs and pngs all the filenames either end in '1' or '2'.
what i want to do is have the program run through all the files and all the files with 1 i then want to copy into either a table or text file (i have not decide yet which but text file seems easier)
and it will insert files ending 2 into another text file/table.
i also want as much file info put into the table as well ie file size, modified date, file type etc
i know that it is probably possible to do this with the filesystemobject. the thing is that most of the tutorials i've seen (and belive me i've seen loads) all concentrate on the web side of using the fso.
if anyone can point me in the right direction as to how to go forward i would be really grateful, as this is the first 'proper' project i've been set by my boss so i want to get it sorted
cheers
-
Oct 2nd, 2002, 12:06 PM
#2
PowerPoster
Try this and let me know if it works for you:
VB Code:
Private Sub Command1_Click()
CheckFolder "c:\temp", "list1.txt", "list2.txt"
End Sub
Public Sub CheckFolder(strFolder As String, strFile1 As String, strFile2 As String)
'===================================================================================
' NOTE: to simplify processing strFile1(2) must have extensions
'===================================================================================
Dim strFile As String
Dim intPos As Integer
On Error GoTo ErrClear
If Not Right(strFolder, 1) = "\" Then strFolder = strFolder & "\"
Open strFolder & strFile1 For Output As #1
Open strFolder & strFile2 For Output As #2
strFile = Dir(strFolder, vbNormal)
Do While strFile <> ""
If strFile <> "." And strFile <> ".." Then
If (GetAttr(strFolder & strFile) And vbNormal) = vbNormal Then
intPos = InStrRev(strFile, ".")
If Not (strFile = strFile1 Or strFile = strFile2) Then
If Mid(strFile, intPos - 1, 1) = "1" Then
Print #1, strFile
Else
Print #2, strFile
End If
End If
End If
End If
strFile = Dir
Loop
Close #1
Close #2
Exit Sub
ErrClear:
'-----------
Err.Clear
Resume Next
End Sub
-
Oct 3rd, 2002, 04:15 AM
#3
Thread Starter
Hyperactive Member
cheers for the reply.
i've tried using your example and it works to a certain extent.
but not how i want it to
i set up a folder called test and put 7 jpgs in it 3 had file names ending in 1 and 4 in two
when i click onthe command button nothing is pushed into the listboxes.
but two text files are created in the test folder list1.txt contains all the jpg file names and list2.txt contains nothing.
what i want is to have a directory structure like so
c:\testfolder\ testfolder1
\testfolder2
\testfolder3
\testfolder4
the program will go through each folder within the testfolder parent folder.
split the jpgs into one group that ends in1 and one that ends in two and puts them into separate files along with as much individual file info as i can get.
so i guess that the easiest way would be t use the filesystemobject in some way. quite how i dont know.
thanks for the help anyway
-
Oct 3rd, 2002, 07:27 AM
#4
PowerPoster
In your original post here's what you said:
... and it will insert files ending 2 into another text file/table ...
So, my example will exactly what you've asked for. Isn't it? But if you want to populate a Listbox instead of spooling to a new file then just modify that procedure. Let me know if you have any problem with doing that.
-
Oct 3rd, 2002, 07:33 AM
#5
PowerPoster
It may look some thing like this:
VB Code:
Private Sub Command1_Click()
CheckFolder "c:\temp", List1, List2
End Sub
Public Sub CheckFolder(strFolder As String, lst1 As ListBox, lst2 As ListBox)
'===================================================================================
Dim strFile As String
Dim intPos As Integer
On Error GoTo ErrClear
If Not Right(strFolder, 1) = "\" Then strFolder = strFolder & "\"
strFile = Dir(strFolder, vbNormal)
Do While strFile <> ""
If strFile <> "." And strFile <> ".." Then
If (GetAttr(strFolder & strFile) And vbNormal) = vbNormal Then
intPos = InStrRev(strFile, ".")
If Mid(strFile, intPos - 1, 1) = "1" Then
lst1.AddItem strFile
Else
lst2.AddItem strFile
End If
End If
End If
strFile = Dir
Loop
Exit Sub
ErrClear:
'-----------
Err.Clear
Resume Next
End Sub
-
Oct 3rd, 2002, 10:06 AM
#6
Thread Starter
Hyperactive Member
cheers for the reply
but
the example you posted just put all the image filenames into the same txt file, with no other info.
and will only search on the level of c:\testing
wheras i would want it to go through c:\testing\testing1, c:\testing\testing2, c:\testing\testing3, etc
i hope this makes sense.
thanks for your help so far
-
Oct 3rd, 2002, 10:37 AM
#7
PowerPoster
OK, use this procedure instead, but KIM: you will need to tune it up.
[bncode]
Public Sub CheckFolder(strFolder As String, lst1 As ListBox, lst2 As ListBox)
'===================================================================================
Dim strFile As String
Dim intPos As Integer
Dim strCurFile As String
On Error GoTo ErrClear
If Not Right(strFolder, 1) = "\" Then strFolder = strFolder & "\"
strFile = Dir(strFolder, vbNormal)
Do While strFile <> ""
If strFile <> "." And strFile <> ".." Then
If (GetAttr(strFolder & strFile) And vbNormal) = vbNormal Then
intPos = InStrRev(strFile, ".")
If Mid(strFile, intPos - 1, 1) = "1" Then
strCurFile = strFolder & strFile
intPos = InStrRev(strCurFile, ".")
lst1.AddItem strFile & vbTab & FileLen(strCurFile) & " bytes" _
& vbTab & FileDateTime(strCurFile) _
& vbTab & Mid(strCurFile, intPos + 1)
ElseIf Mid(strFile, intPos - 1, 1) = "2" Then
strCurFile = strFolder & strFile
intPos = InStrRev(strCurFile, ".")
lst2.AddItem strFile & vbTab & FileLen(strCurFile) & " bytes" _
& vbTab & FileDateTime(strCurFile) _
& vbTab & Mid(strCurFile, intPos + 1)
End If
End If
End If
strFile = Dir
Loop
Exit Sub
ErrClear:
'-----------
Debug.Print Err.Description
Err.Clear
Resume Next
End Sub
[/Highlight]
-
Oct 3rd, 2002, 10:37 AM
#8
PowerPoster
Just re-posting it:
VB Code:
Public Sub CheckFolder(strFolder As String, lst1 As ListBox, lst2 As ListBox)
'===================================================================================
Dim strFile As String
Dim intPos As Integer
Dim strCurFile As String
On Error GoTo ErrClear
If Not Right(strFolder, 1) = "\" Then strFolder = strFolder & "\"
strFile = Dir(strFolder, vbNormal)
Do While strFile <> ""
If strFile <> "." And strFile <> ".." Then
If (GetAttr(strFolder & strFile) And vbNormal) = vbNormal Then
intPos = InStrRev(strFile, ".")
If Mid(strFile, intPos - 1, 1) = "1" Then
strCurFile = strFolder & strFile
intPos = InStrRev(strCurFile, ".")
lst1.AddItem strFile & vbTab & FileLen(strCurFile) & " bytes" _
& vbTab & FileDateTime(strCurFile) _
& vbTab & Mid(strCurFile, intPos + 1)
ElseIf Mid(strFile, intPos - 1, 1) = "2" Then
strCurFile = strFolder & strFile
intPos = InStrRev(strCurFile, ".")
lst2.AddItem strFile & vbTab & FileLen(strCurFile) & " bytes" _
& vbTab & FileDateTime(strCurFile) _
& vbTab & Mid(strCurFile, intPos + 1)
End If
End If
End If
strFile = Dir
Loop
Exit Sub
ErrClear:
'-----------
Debug.Print Err.Description
Err.Clear
Resume Next
End Sub
-
Oct 3rd, 2002, 11:11 AM
#9
Thread Starter
Hyperactive Member
thanks again
but
it still puts all file (ending in 1 and 2) in the same place where as i want them in separate files
it also does not search the sub directories testing1, testing2, etc
it only searchs the folder that i set checkfolder not all the files in all the directories
thanks again
-
Oct 3rd, 2002, 11:21 AM
#10
PowerPoster
sagey,
you must understand one thing: no one here will give a final solution but some example to answer your question as close as possible. You will need to modify sample code to get it to work the way you want. And then if you still have some issues give us a buzz ... But you will need to show us your version of whatever that isn't "cooperating" with your logic.
;-)
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
|