Check for, Create Directory

mfabian
Member Posts: 187
The folowing routine solves the problem:
Does a directory <SearchDirectory> exist? If not, create it.
Var
SearchDirectory : Text200
rtFileSystem : Automation 'Microsoft Scripting Runtime'.FileSystemObject
Begin
SearchDirectory := 'C:\Temp\testdirectory';
CREATE(rtFileSystem);
IF NOT rtFileSystem.FolderExists(SearchDirectory) THEN
rtFileSystem.CreateFolder(SearchDirectory);
end;
Marcus
Marcus Fabian
m.fabian@thenet.ch
+41 79 439 78 72
Does a directory <SearchDirectory> exist? If not, create it.
Var
SearchDirectory : Text200
rtFileSystem : Automation 'Microsoft Scripting Runtime'.FileSystemObject
Begin
SearchDirectory := 'C:\Temp\testdirectory';
CREATE(rtFileSystem);
IF NOT rtFileSystem.FolderExists(SearchDirectory) THEN
rtFileSystem.CreateFolder(SearchDirectory);
end;
Marcus
Marcus Fabian
m.fabian@thenet.ch
+41 79 439 78 72
With best regards from Switzerland
Marcus Fabian
Marcus Fabian
1
Comments
-
very useful code, thanks. there is just one problem. if the directory Temp doesn't exists you will get an error. It seems that navision can only handle one directory at the time.0
-
rwabel wrote:very useful code, thanks. there is just one problem. if the directory Temp doesn't exists you will get an error. It seems that navision can only handle one directory at the time.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
rwabel wrote:very useful code, thanks. there is just one problem. if the directory Temp doesn't exists you will get an error. It seems that navision can only handle one directory at the time.
This function recursively creates the whole structure if necessary.FUNCTION CreateSubdir(ItxtSubdir : Text[1024]) // CreateSubdir // Creates a subdir if it doesn't exist, it creates the whole path if necessary // PARAMETERS: // ItxtSubdir : Full path of directory to create IF STRLEN(ItxtSubdir) <= 2 THEN // ('X:') EXIT; Lint := STRLEN(ItxtSubdir); WHILE (Lint > 0) AND (COPYSTR(ItxtSubdir,Lint,1) <> '\') DO BEGIN Lint -= 1; END; IF Lint = 0 THEN EXIT; // no 'X:\' found CreateSubdir(COPYSTR(ItxtSubdir,1,Lint - 1)); CREATE(LAutFileSystemObject); IF NOT LAutFileSystemObject.FolderExists(ItxtSubdir) THEN LAutFileSystemObject.CreateFolder(ItxtSubdir);
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
-
Savatage wrote:You're a code machine \:D/
Shame my parents forgot to order some memory...
PS I send to Luc "How to use recursion in Navision" with some theory, remarks and some basic and Navision examples.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
kriki wrote:I changed the code of fabian a little.
This function recursively creates the whole structure if necessary.FUNCTION CreateSubdir(ItxtSubdir : Text[1024]) // CreateSubdir // Creates a subdir if it doesn't exist, it creates the whole path if necessary // PARAMETERS: // ItxtSubdir : Full path of directory to create IF STRLEN(ItxtSubdir) <= 2 THEN // ('X:') EXIT; Lint := STRLEN(ItxtSubdir); WHILE (Lint > 0) AND (COPYSTR(ItxtSubdir,Lint,1) <> '\') DO BEGIN Lint -= 1; END; IF Lint = 0 THEN EXIT; // no 'X:\' found CreateSubdir(COPYSTR(ItxtSubdir,1,Lint - 1)); CREATE(LAutFileSystemObject); IF NOT LAutFileSystemObject.FolderExists(ItxtSubdir) THEN LAutFileSystemObject.CreateFolder(ItxtSubdir);
thanks a lot for the recursive function. But when I use it I get the following error message: "This message is for C/AL programmers: Variable already created."
When you addIF ISCLEAR(LAutFileSystemObject) THEN
before the CREATE it should work fine0 -
rwabel wrote:CREATE(LAutFileSystemObject);
IF NOT LAutFileSystemObject.FolderExists(ItxtSubdir) THEN
LAutFileSystemObject.CreateFolder(ItxtSubdir);[/code]
thanks a lot for the recursive function. But when I use it I get the following error message: "This message is for C/AL programmers: Variable already created."
Forgot to write this: the variable LAutFileSystemObject must be a local one, not a global.Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
kriki wrote:rwabel wrote:CREATE(LAutFileSystemObject);
IF NOT LAutFileSystemObject.FolderExists(ItxtSubdir) THEN
LAutFileSystemObject.CreateFolder(ItxtSubdir);[/code]
thanks a lot for the recursive function. But when I use it I get the following error message: "This message is for C/AL programmers: Variable already created."
Forgot to write this: the variable LAutFileSystemObject must be a local one, not a global.
much better than doing the ISCLEAR stuff :-) thanks for the hint0
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