Files can be deleted with the f_delete command. This takes two arguments the first is a boolean varaible which is set to true if the delete is completed without an error and the second is the file name to delete. In the following line of code Deleted would get set to true if TestFile.csv was deleted correctly.
f_delete Deleted “TestFile.csv”
To rename a file use the f_rename command the first argument is a boolean which gets set to true if the rename is succesfull, the second argument is the new file name and the third argument is the existing path and filename.
f_rename RenamedOk “NewName.e” “OldName.e”
To copy a file use the f_copy command the first argument is the destination and the second argument is the location to copy the file from.
f_copy CopiedOk “c:\NewLocation\NewName.e” “c:\OldLocation\OldName.e”
A directory can be read using the directory_get command the command has two arguments the first is a string variable to place the contents of the directory into and the second is the path of the directory. The following code will list the contents of TestDir.
directory_get Listing "c:\TestDir\*"
lst_size NumberItems Listing
i = 0
while i < NumberItems
outl Listing[i]
++ i
_while
A new directory can be created using the dir_make command. The command takes two arguments the first returns true if the directory is created and the second one is the path for the new directory.
dir_make DirOk “NewDirectory”
A new directory can be created using the directory_remove command. The command takes two arguments the first returns true if the directory is created and the second one is the path for the directory to remove.
directory_remove RemovedOk “NewDirectory”
The following file creates a new directory, adds 2 files to the directory, copies one of the files, renames the file then displays the files in the directory. It then deletes the files and finally the directory.
//---------------------------------------
// File: Directory.e
//---------------------------------------
//---------------------------------------
// Block: CreateFile
//---------------------------------------
// Variables:
// FileName
// Text
//---------------------------------------
block CreateFile FileName Text
//Add a couple of files
//open the file
fo_open Check FileName
//check file is open
if Check == true
out "Created " FileName
new_line
_if
//write some data
fo_write Text
fo_close
_block
//---------------------------------------
// Block: DeleteFile
//---------------------------------------
// Variables:
// FileName
//---------------------------------------
block DeleteFile FileName
f_delete Check FileName
if Check == true
out "Deleted " FileName
new_line
_if
_block
//---------------------------------------
// Block: go
//---------------------------------------
block Go
//Create directory
dir_make Check "TestDir"
if Check == true
out "Created directory"
new_line
else
outl "Not Created directory does it already exist?"
exit_program
_if
//create a couple of files
CreateFile "TestDir\deleteme1.txt" "Test1"
CreateFile "TestDir\deleteme2.txt" "Test2"
//copy a file
f_copy Check "TestDir\deleteme3.txt" "TestDir\deleteme2.txt"
if Check == true
outl "TestDir\deleteme2.txt copied to TestDir\deleteme3.txt"
_if
//rename a file
f_rename Check "TestDir\deleteme4.txt" "TestDir\deleteme3.txt"
if Check == true
outl "TestDir\deleteme3.txt renamed to TestDir\deleteme4.txt"
_if
//get the directory
dir_get Listing "TestDir\*"
lst_size NumberItems Listing
new_line
I = 0
while I < NumberItems
outl Listing[I]
++ I
_while
new_line
//delete the files
DeleteFile "TestDir\deleteme1.txt"
DeleteFile "TestDir\deleteme2.txt"
DeleteFile "TestDir\deleteme4.txt"
//delete the directory
dir_remove Check "TestDir"
if Check == true
out "Deleted directory"
new_line
_if
_block
If you want to allow a user to get a filename then the f_getname command opens the File Manager used by evolve console this allows them to navigate to the required file and when selected will return the file name.
//---------------------------------------
// File: FileManager.e
//---------------------------------------
//---------------------------------------
// Block: Go
//---------------------------------------
block Go
f_getname FileName
if FileName != ""
outl "You selected " FileName
else
outl "No File Selected"
_if
_block
If you want to allow a user to get a filename then the f_getname command opens the File Manager used by evolve console this allows them to navigate to the required file and when selected will return the file name.
//---------------------------------------
// File: DirNavigation.e
//---------------------------------------
//---------------------------------------
// Block: Go
//---------------------------------------
block Go
f_getdir DirName
if DirName != ""
outl "You selected " DirName
else
outl "No Directory Selected"
_if
_block