|
-
October 22nd, 2001, 02:09 PM
#1
Saving Problem
When I run the following code, it tries to write to files which aren't folders. I only want it to save the file in the folders under that directory. Help would be appreciated.
_____________________
option Explicit
private Sub Command1_Click()
Dim strFolder as string
Dim strtPoint as string
strtPoint = "C:\My Documents"
strFolder = Dir(strtPoint & "\*.*", vbDirectory)
Do
If strFolder <> "." And strFolder <> ".." then ' bypass system folders
If GetAttr(strtPoint & "\" & strFolder) And vbDirectory = vbDirectory then ' This a Directory
Open strtPoint & "\" & strFolder & "\title.txt" for Output as #1
print #1, "Message"
Close #1
End If
End If
strFolder = Dir ' get next in chain
Loop Until strFolder = "" ' do it again
End Sub
-
October 22nd, 2001, 02:42 PM
#2
Re: Saving Problem
Here is the problem
If (GetAttr(strtPoint & "\" & strFolder) And vbDirectory) = vbDirectory then ' This a Directory
Hope this helps
TB_Guy_2000
-
October 22nd, 2001, 06:26 PM
#3
Re: Saving Problem
What I see is that any folder that is a subFolder of "My Documents" will end up with a one line file called "Title.txt"
Where do you want "Title.txt" to end up at and how many copies do you want?
On my System the "My DOcuments" has three subfolders called "My Picturees", "My eBooks" and "My Music". All tree ended up with that file in it.
John G
-
October 22nd, 2001, 08:46 PM
#4
Re: Saving Problem
That's exactly what I wanted except now I have a new problem. I need to be able to have more than one directory (ex. My Documents and Misc Folder). Here's my code again.
__________
option Explicit
private Sub Command1_Click()
Dim strFolder as string
Dim strtPoint as string
strtPoint = "C:\Directory"
strFolder = Dir(strtPoint & "\*.*", vbDirectory)
Do
If strFolder <> "." And strFolder <> ".." then ' bypass system folders
If (GetAttr(strtPoint & "\" & strFolder) And vbDirectory) = vbDirectory then ' This a Directory
Open strtPoint & "\" & strFolder & "\file.txt" for Output as #1
print #1, "Text"
Close #1
End If
End If
strFolder = Dir ' get next in chain
Loop Until strFolder = "" ' do it again
End Sub
-
October 23rd, 2001, 07:26 AM
#5
Re: Saving Problem
Simply put the code into a subroutine then call the subroutine from Command1_Click passing the name of the starting folder like so.
option Explicit
'
private Sub Command1_Click()
SaveToFolder "C:\My Documents"
SaveToFolder "C:\Misc Folder"
End Sub
'
public Sub SaveToFolder(strtPoint as string)
'
Dim strFolder as string
strFolder = Dir(strtPoint & "\*.*", vbDirectory)
Do
If strFolder <> "." And strFolder <> ".." then ' bypass system folders
If GetAttr(strtPoint & "\" & strFolder) And vbDirectory = vbDirectory then ' This a Directory
Open strtPoint & "\" & strFolder & "\title.txt" for Output as #1
print #1, "Message"
Close #1
End If
End If
strFolder = Dir ' get next in chain
Loop Until strFolder = "" ' do it again
End Sub
John G
-
October 23rd, 2001, 09:50 AM
#6
Re: Saving Problem
If GetAttr(strtPoint & "\" & strFolder) And
vbDirectory = vbDirectory then ' This a Directory
The second part of this condition seems useless.
VbDirectory always equals vbDirectory
Nicolas Bohemier
-
October 24th, 2001, 07:46 PM
#7
Re: Saving Problem
How can I make it so that the program will write to system folders?
-
October 25th, 2001, 02:49 PM
#8
Re: Saving Problem
Slight error in my sample. Relplace similiar line with this one. See positioning of right parenthesis
If GetAttr(strtPoint & "\" & strFolder And vbDirectory) = vbDirectory then ' This a Directory
John G
-
October 25th, 2001, 02:50 PM
#9
Re: Saving Problem
Misplaced Right Parenthesis. It should read
If GetAttr(strtPoint & "\" & strFolder) And vbDirectory = vbDirectory then ' This a Directory
THanks for pointing that out
John G
-
October 25th, 2001, 02:51 PM
#10
Re: Saving Problem
A correction to my correction.
If GetAttr(strtPoint & "\" & strFolder And vbDirectory) = vbDirectory then ' This a Directory
John G
-
October 25th, 2001, 03:02 PM
#11
Re: Saving Problem
There seems to be some confusion regarding positioning of parenthesis in my original post so here is is again with some clarification (Additional left - right parenthesis). The original post is correct. It takes the output of the GetAttr function "ands" the result with vbDirectory then compares the results with vbDirectory.
Disregard my corrections and corrections to the corrections.
option Explicit
'
private Sub Command1_Click()
SaveToFolder "C:\My Documents"
End Sub
'
public Sub SaveToFolder(strtPoint as string)
'
Dim strFolder as string
strFolder = Dir(strtPoint & "\*.*", vbDirectory)
Do
If strFolder <> "." And strFolder <> ".." then ' bypass system folders
If (GetAttr(strtPoint & "\" & strFolder) And vbDirectory) = vbDirectory then ' This a Directory
Open strtPoint & "\" & strFolder & "\title.txt" for Output as #1
print #1, "Message"
Close #1
End If
End If
strFolder = Dir ' get next in chain
Loop Until strFolder = "" ' do it again
End Sub
John G
-
October 25th, 2001, 03:04 PM
#12
Re: Saving Problem
I know of no reason why you can't read to a system folder unless they are password protected or are made readonly for some reason.
I am not familiar with Windows NT or Windows 2000 so if you are using those I can not help.
John G
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
|