if folder not exist, create a new

cure
Member Posts: 77
Hi
I'm looking for a function witch can see, if the folder all ready exist. If not, the function has to create this order.
Can you help me?
regards
curdin
I'm looking for a function witch can see, if the folder all ready exist. If not, the function has to create this order.
Can you help me?
regards
curdin
0
Comments
-
Hi Cure
set a variable as follows
Name DataType Subtype Length
FileSystem Automation 'Microsoft Scripting Runtime'.FileSystemObject
code to check if exists
IF ISCLEAR(FileSystem) THEN
CREATE(FileSystem);
IF NOT FileSystem.FolderExists(Foldername) THEN
FileSystem.CreateFolder(Foldername);
Hope this gets you going :P0 -
Hi Albertvh
Everythings works fine, but the program has a problem to create the New Folder. Manually I've permission to create a folder.
The ErrorMessage looks like thatAn exeption was raised in method CreateFolder. The OLE control or Automation server has returned error (HRESULT) -2147352567. The component did not provide the exception description.
Whats wrong? The check, if the folder exists work well. Only create a new folder give me some problems. Is there any other way to create an folder??
Thank you very much0 -
The mentioned code might give a problem if you want to create several levels at once. Also in Windows/Dos you can't do this.
example:
if is missing c:\level1\level2\level3
then create c:\level1\level\level3 will give a problem if c:\level1\level does not exists.
You need to do that check in a loop
test if c:\ exists
if so
test if c:\level1 exists
if not create
test if c:\level1\level2 exists
if not create
test if c:\level1\level2\level3 exists
if not create
Then this will work (ALLWAYS)0 -
Thank you for the information about the Automation Server.
But I don't like to step through the folder structure to create several subfolders.
Here is my solution:
CheckLocalFolder(Folder : Text[250])IF ISCLEAR(FileSysObj) THEN CREATE(FileSysObj); IF NOT FileSysObj.FolderExists(Folder) THEN BEGIN BatchFileName := GeneralMgt.AppendBacksl(ENVIRON('tmp'))+'nav_mkdir_batch.cmd'; IF EXISTS(BatchFileName) THEN BEGIN ERASE(BatchFileName); YIELD; END; BatchFile.CREATE(BatchFileName); BatchFile.WRITE('mkdir ' + Folder); BatchFile.CLOSE; YIELD; SHELL(BatchFileName); ERASE(BatchFileName); END;
Works fine :-)
For the sake of completeness here the used AppendBacksl procedure:
AppendBacksl(_Input : Text[249]) : Text[250]// Check for ending backslash of folder name IF _Input = '' THEN EXIT('\'); IF NOT (COPYSTR(_Input,STRLEN(_Input)) = '\') THEN EXIT(_Input + '\');
hthX[1]:=126;X[2]:=67;X[3]:=47;X[4]:=65;X[5]:=76;X[6]:=32;X[7]:=114;X[8]:=111;X[9]:=120;X[10]:=120;X[11]:=120;X[12]:=126;
FOR I:=1 TO 12 DO S+=X;MESSAGE(S);0 -
Hi,
Jascha Vincke
i used ur code to create a folder but variable used
GeneralMgt.AppendBacksl(ENVIRON('tmp'))+'nav_mkdir_batch.cmd';
what is that?
Any codeunit or what?
Plz reply0 -
Hi shraddha,
this is Codeunit 11501 and the method AppendBacksl() is a modified copy of the existing method CheckFolderName(). CheckFolderName() only display a Message. The new function appends a backslash if the string does not contain a backslash. This is more useful instead of a message i think ;-)
hth
Jascha
//edit: We use a german NAV database. I don't know if u have this Codeunit (11501) in your local version. If you look at my previous post you'll see the code for the method AppendBacksl() to add it to an object you prefer.X[1]:=126;X[2]:=67;X[3]:=47;X[4]:=65;X[5]:=76;X[6]:=32;X[7]:=114;X[8]:=111;X[9]:=120;X[10]:=120;X[11]:=120;X[12]:=126;
FOR I:=1 TO 12 DO S+=X;MESSAGE(S);0 -
Hi,
codeunit 11501 not exist in my DB
#-o0 -
After years my little script stopped working some day because computers compute way more faster as in the days I created my CheckLocalFolder() method.
So here comes the update:
Add SLEEP(250); two times!
Before SHELL(BatchFileName);
And before ERASE(BatchFileName);.
waaa *sleeeeep* \:D/X[1]:=126;X[2]:=67;X[3]:=47;X[4]:=65;X[5]:=76;X[6]:=32;X[7]:=114;X[8]:=111;X[9]:=120;X[10]:=120;X[11]:=120;X[12]:=126;
FOR I:=1 TO 12 DO S+=X;MESSAGE(S);0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions