469,077 Members | 1,424 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,077 developers. It's quick & easy.

Making A Folder to place a text file in Code

lee123
556 512MB
Hi there i was wondering how you make a folder in code to place a text document. another words, i want to create a folder for a text file i create so when iim done with writing the txt file it will create a folder to store it in. But i don't know how to do this this is my code.

Create My Folder:

Expand|Select|Wrap|Line Numbers
  1. Private Sub newfolder()
  2.     'This is the folder I want to create
  3. '----------------------------------------------------------------------
  4.     Dim ofilesys As New FileSystemObject
  5.     Dim ofolder As Folder
  6.     Set ofolder = ofilesys.CreateFolder("C:\Program Files\MyDiary")
  7. End Sub
Place Folder In this But Where?

Expand|Select|Wrap|Line Numbers
  1. Private Sub SaveToLog()
  2.  
  3. ' I want the created folder to be in here somewhere but WHERE!
  4. '-------------------------------------------------------------
  5. Dim ff
  6. ff = FreeFile
  7. Open "C:\MyDiary.txt" For Append As #ff
  8. Print #ff, vbNewLine; "Name" & " " & User; vbNewLine _
  9. & " " & "Subject" & "  " & Subject; vbNewLine _
  10. & " " & "Date" & "  " & DateOfEntry; vbNewLine _
  11. & " " & "Log Entry: " & "  " & Log; vbNewLine _
  12. ; vbNewLine; DiaryLog & "  " & vbNewLine; Now(); vbNewLine
  13. Close #ff
  14.     Shell "Notepad.exe C:\MyDiary.txt", vbNormalFocus
  15.     DiaryLog.Text = ""
  16.     User.Text = ""
  17.     Log.Text = ""
  18.     Subject.Text = ""
  19.     User.SetFocus
  20. End Sub
I hope this explains it all if not tell me and i will try again.

lee123
Apr 13 '09 #1
4 1364
lee123
556 512MB
doesn't anybody know how to do this, on this site...
Apr 15 '09 #2
QVeen72
1,445 Expert 1GB
Hi,

Use this code, to make folder (Code without FSO) :

Expand|Select|Wrap|Line Numbers
  1. Dim FoldName As String
  2. FoldName = "C:\MyFolder"
  3. If Trim(Dir(FoldName,vbDirectory)) ="" Then
  4.     MkDir FoldName
  5. End if
  6.  
Regards
Veena
Apr 15 '09 #3
lee123
556 512MB
ok i have put this in the code. i hope it's in the right area, but how do i put the text file in there (Folder)

Code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub SaveToLog()
  2.     Dim MyDiary As String
  3.     Dim ff
  4.     ff = FreeFile
  5.         Open "C:\My Diary.txt" For Append As #ff
  6.         Print #ff, "Name" & "  " & User; vbNewLine _
  7.             & " " & "Subject" & "   " & Subject; vbNewLine _
  8.             & " " & "Date" & "   " & DateOfEntry; vbNewLine _
  9.             & " " & "Log Entry: " & "   " & Log; vbNewLine _
  10.             ; vbNewLine; DiaryLog & "   " & vbNewLine; Now(); vbNewLine
  11.         Close #ff
  12.             Shell "Notepad.exe C:\My Diary", vbNormalFocus
  13.             DiaryLog.Text = ""
  14.             User.Text = ""
  15.             Log.Text = ""
  16.             Subject.Text = ""
  17.             User.SetFocus
  18.  
  19.             MyDiary = "C:\MyDiary"
  20.             If Trim(Dir(MyDiary, vbDirectory)) = "" Then
  21.                 MkDir MyDiary
  22.             End If
  23. End Sub
lee123
Apr 15 '09 #4
lee123
556 512MB
Since there is no response i guess this isn't possible to do.

thanks anyway!!!!

lee123
Apr 16 '09 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Josh | last post: by
4 posts views Thread by Pavel | last post: by
5 posts views Thread by jasonburrwc84 | last post: by
8 posts views Thread by Topper | last post: by
9 posts views Thread by Keith G Hicks | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.