|
-
May 5th, 2000, 02:22 AM
#1
I am writing a program that will save data to a sequential file. Everything works just fine if the user has the directory and the file in that directory on their computer already, but how do I create the directory and file if it doesn't exist? I want to check on the form load event to see if there is one there, and if not, create the folder, and file(blank). If it does exist, then I want to do nothing. I would like to do everything from the same form, no modules, and no api calls. Any help? I can't seem to find this. It is probably some real simple commands....
-
May 5th, 2000, 02:46 AM
#2
Lively Member
Here try this
if dir(c:\file\file.txt) = "" then 'Looks for file
a = shell("mkdir file")
Open "c:\file\file.txt" For Output As #12
Print #12, " "
close #12
end if
what it does is looks for the file if its not there creates the dir then makes a blank file.
Hope it helps
Brooke Hostmeyer
-------------------------
There is never only one right answer. That is the magic of programming.
-------------------------
-
May 5th, 2000, 02:51 AM
#3
transcendental analytic
mkdir statement is available in vb
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
May 5th, 2000, 03:02 AM
#4
Addicted Member
-
May 5th, 2000, 05:45 AM
#5
jcourure100, no good. It didn't recognize FileSystemObject. Am I doing something wrong? I cut and pasted the code you gave (and added the correct folder and file names).
BHostmeyer,
I am getting some errors with yours too. I get the runtime error when it processes
a = shell("mkdir file")
Should I have changed anything in there, or is this what it was supposed to be?
Thanks for your help, I do appreciate it, even if I can't make it work. lol
-
May 5th, 2000, 08:27 AM
#6
Lively Member
I think you haven't put the reference to the dll yet. Instead, may be you want to try the createobject("FileSystemObject.Scripting")...I think.
-
May 5th, 2000, 09:22 AM
#7
Addicted Member
Wow, jcouture100, you really like the MS Scripting Runtime
library, I've seen you suggest it on a few posts now. Sorry
to tell you, but I don't see any reason to include a 149KB
DLL that only wraps some of the functionality
already built into VB's file system functions and the core
system libraries (kernel32.dll to be exact). It's good for
beginners learning how to use the file system, but you
should move on as soon as you feel comfortable. I mean it
doesn't allow Binary file processing or Random Access!
Sorry to say it, but it's time to move on.
Just my 2¢
Dan PM
Analyst Programmer
VB6 SP3 (also VB4 16-bit sometimes  )
-
May 6th, 2000, 10:46 AM
#8
Addicted Member
You're right about that, Dan. To be honest with you, I personally don't use the FSO and pretty much stick with the route you suggested. I'm rather addicted to API calls and try to use them whenever possible.
But considering that HellsWraith is a beginner I thought it would be nice to not totally overwhelm him, but still give him something new to learn. Using the FSO has got to be better than Shelling out and running the MKDIR Command.
HellsWraith, lychew is correct. It sounds like the reference to the FileSystemObject contained in the scrrun.dll. To set this reference, you need to do the following:
Click on the PROJECT menu, then Click on the REFERENCES submenu. This will open up a window that lets you pick the various DLLs that you want referenced in your project. Scroll down until you find "Microsoft Scripting Runtime" and make sure the check box is checked. Click OK. Now the code I gave you earlier should work.
If you're interested in the calls mentioned by Dan (SonGouki) I'll be glad to send them to you. They are actually very easy to implement and use.
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
|