I do not know if there is any better (more elegant :-)) way how to create directory from C/AL code than this, but I am using this ways:
both examples use standard DOS function MD (make dir)
1) you can use SHELL function like this:
SHELL('MD <<path of directory>>');
2) if first example does not work, you need to create a MS-DOS BAT file and call it from C/AL
filBat is C/AL variable, type FILE
creating file:
filBat.CREATE(<<some path to temp file>> + '<<filename.bat>>');
filBat.WRITEMODE(TRUE);
filBat.TEXTMODE(TRUE);
filBat.WRITE('@ECHO OFF');
filBat.WRITE('MD ' + <<path of direcory, which will be created>>');
filBat.WRITE('@ECHO OFF'); /// important, without this command, on Win9X system after execution of this batch remains opened window of finished job
filBat.CLOSE;
call batch file
SHELL('<<batch file>>');
delete batch file, which is redundand at this time, because directory was created
ERASE(<<batch file>>);
exact description, syntax and parameters of all C/AL statements can be found in on-line help for C/AL
I think I helped U
If anyone knows better solution of this problem, write it there.
I use it like described except instead of MD I use the XCOPY command.
I create a new job-directory by copying (XCOPY) a default directory to a new directory with the name of the job no.
Works like a charm! 8)
Use the 'Windows Script Host Object Model'.FileSystemObject'
CreateFolder(NewFolder : Text[100]) : Boolean
IF ISCLEAR(FileSystem) THEN
IF NOT CREATE(FileSystem) THEN
EXIT;
FileSystem.CreateFolder(NewFolder);
For creating 1 folder this (filesystem) is the easiest solution. But for copying 24 folders I think the solution with the batchfile and xcopy works faster. Or is it possible to do this with FileSystem? I'll have a look myself.
Btw. I have used WindowsShell.Explore(FolderName) for opening a folder like the way you described.
And I added a CLEAR(FileSystem); before IF ISCLEAR, because else I couldn't open the folder two times from the same form.
Use the 'Windows Script Host Object Model'.FileSystemObject'
CreateFolder(NewFolder : Text[100]) : Boolean
IF ISCLEAR(FileSystem) THEN
IF NOT CREATE(FileSystem) THEN
EXIT;
FileSystem.CreateFolder(NewFolder);
For creating 1 folder this (filesystem) is the easiest solution. But for copying 24 folders I think the solution with the batchfile and xcopy works faster. Or is it possible to do this with FileSystem? I'll have a look myself.
Btw. I have used WindowsShell.Explore(FolderName) for opening a folder like the way you described.
And I added a CLEAR(FileSystem); before IF ISCLEAR, because else I couldn't open the folder two times from the same form.
I am using this code to create a group of over 100 folders.
Use the 'Windows Script Host Object Model'.FileSystemObject'
CreateFolder(NewFolder : Text[100]) : Boolean
IF ISCLEAR(FileSystem) THEN
IF NOT CREATE(FileSystem) THEN
EXIT;
FileSystem.CreateFolder(NewFolder);
For creating 1 folder this (filesystem) is the easiest solution. But for copying 24 folders I think the solution with the batchfile and xcopy works faster. Or is it possible to do this with FileSystem? I'll have a look myself.
Btw. I have used WindowsShell.Explore(FolderName) for opening a folder like the way you described.
And I added a CLEAR(FileSystem); before IF ISCLEAR, because else I couldn't open the folder two times from the same form.
I am using this code to create a group of over 100 folders.
Ok. Are there files in those folders?
If so, you copy them by using file.COPY?
Thanks for the input!
In my situation I am creating a bunch of files in a group of folders. The above code is used to create any folders that are missing. The folder names are based on records in Navision.
I am then using
FileSystem.MoveFile(Path + Filename, NewPath + Filename);
Comments
I do not know if there is any better (more elegant :-)) way how to create directory from C/AL code than this, but I am using this ways:
both examples use standard DOS function MD (make dir)
1) you can use SHELL function like this:
SHELL('MD <<path of directory>>');
2) if first example does not work, you need to create a MS-DOS BAT file and call it from C/AL
filBat is C/AL variable, type FILE
creating file:
filBat.CREATE(<<some path to temp file>> + '<<filename.bat>>');
filBat.WRITEMODE(TRUE);
filBat.TEXTMODE(TRUE);
filBat.WRITE('@ECHO OFF');
filBat.WRITE('MD ' + <<path of direcory, which will be created>>');
filBat.WRITE('@ECHO OFF'); /// important, without this command, on Win9X system after execution of this batch remains opened window of finished job
filBat.CLOSE;
call batch file
SHELL('<<batch file>>');
delete batch file, which is redundand at this time, because directory was created
ERASE(<<batch file>>);
exact description, syntax and parameters of all C/AL statements can be found in on-line help for C/AL
I think I helped U
If anyone knows better solution of this problem, write it there.
I use it like described except instead of MD I use the XCOPY command.
I create a new job-directory by copying (XCOPY) a default directory to a new directory with the name of the job no.
Works like a charm! 8)
Tino Ruijs
Microsoft Dynamics NAV specialist
CreateFolder(NewFolder : Text[100]) : Boolean
IF ISCLEAR(FileSystem) THEN
IF NOT CREATE(FileSystem) THEN
EXIT;
FileSystem.CreateFolder(NewFolder);
For creating 1 folder this (filesystem) is the easiest solution. But for copying 24 folders I think the solution with the batchfile and xcopy works faster. Or is it possible to do this with FileSystem? I'll have a look myself.
Btw. I have used WindowsShell.Explore(FolderName) for opening a folder like the way you described.
And I added a CLEAR(FileSystem); before IF ISCLEAR, because else I couldn't open the folder two times from the same form.
Tino Ruijs
Microsoft Dynamics NAV specialist
I am using this code to create a group of over 100 folders.
Ok. Are there files in those folders?
If so, you copy them by using file.COPY?
Thanks for the input!
Tino Ruijs
Microsoft Dynamics NAV specialist
I am then using
FileSystem.MoveFile(Path + Filename, NewPath + Filename);
to move the files to another folder.
In the meanwhile I saw FileSystem has more than enough options to do everything I want.
Tino Ruijs
Microsoft Dynamics NAV specialist