Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VFP8 - How to create a new folder

Status
Not open for further replies.

kmagy

MIS
Oct 21, 2003
38
JO
Hi every body;

Please if any body knows how to create a new folder Programmaticaly using VFP8.

Thanks all in advance
 
MD "C:\NewFolder1"

*!* ...or... *!*

MKDIR "C:\NewFolder2"


Slighthaze = NULL
[sub]craig1442@mchsi.com[/sub][sup]
"Whom computers would destroy, they must first drive mad." - Anon​
[/sup]
 
kmagy

To expand on what slighthaze has said, you can test for the existence of a folder and then create it if it does not.

lcFolder = [E:\My new folder]
IF !DIRECTORY(lcFolder)
[tab]ON ERROR llError = .T.
[tab]MD (lcFolder)
[tab]ON ERROR DO Errortrap WITH ;
[tab][tab]SYS(16),;
[tab][tab]LINENO(),;
[tab][tab]ERROR(),;
[tab][tab]MESSAGE(1),;
[tab][tab]MESSAGE
ENDI

IF llError
[tab]llError = .F.
[tab]MESSAGEBOX([Unable to create folder])
ENDI

If you have VFP 8.0 you can use the TRY...CATCH...FINALLY command instead to trap any errors.


FAQ184-2483 - answering getting answered.​
Chris [pc2]
 
Remember that MD (MKDIR) can only add one level of directory at a time, you'll need to "loop" Chris's code for the generic case of a "make directory" like "c:\folder1\folder1a\folder1b\folder1c\".

Rick
 
faq184-4140 Examples of Window Scripting uses in VFP

From FAQ:
How to create a folder
fso = createobject("Scripting.FileSystemObject")
fldr = fso.CreateFolder("C:\MyTest")

Brian
 
Remember that MD (MKDIR) can only add one level of directory at a time,

Actually, I discovered recently that it can add several levels at a time... This:

MD C:\Temp\Jnk\jnk\jnk\jnk

...works fine
 
wgcs,
You are right, it really works! Well, it's either a "senior" moment/memory, or there were circumstances that made me write the "looping" code - I'll have to investigate this.

Rick


 
I think it was added in VFP5 or VFP6... I remember it failing sometime in the past, and once in VFP6 I started to write the looping code, but made a mistake and it worked anyway....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top