File read/write/delete problems
annuello
Posts: 294
Gday all,
I'm reading & writing to files on the local CF card (NI-3000). I seem to be having some difficulties with several of the file commands. These examples are taken straight from the help file.
1. The file_createdir('\CDLIST\TEMP\') function returns -4 (invalid path directory) when trying to create BOTH directories. If I create the '\CDLIST\' directory first, then the subsequent 'TEMP' directory is created okay. The help files indicate that the subdirectories will be created to complete the path...
Okay so the directory now exists. I create a file using file_open('\CDLIST\TEMP\test.txt', 3), which works fine. I then close the file... No dramas.
2. The file_delete('\CDLIST\TEMP\*.*') function returns -5 (disk I/O error). Try as I might, I can not seem to be able to delete the file. I noticed that file_delete() works fine if the target file is not in any subdirectory.
3. The all-dangerous file_removedir('\CDLIST\TEMP\') also has no effect. Another -5 (disk I/O error)
Am I missing something, or is there an issue with the way directories are dealt with? There is plenty of space on the CF. There doesn't appear to be an equivalent command to change the current working directory, to allow me to use relative path names.
I think the help files & NetLinx Programming Language pdf could be a little bit more descriptive in this area. It probably warrants a seperate chapter to the topic.
NLS v2.3, NI-3000 running v2.31.137
Yours,
Roger McLean.
I'm reading & writing to files on the local CF card (NI-3000). I seem to be having some difficulties with several of the file commands. These examples are taken straight from the help file.
1. The file_createdir('\CDLIST\TEMP\') function returns -4 (invalid path directory) when trying to create BOTH directories. If I create the '\CDLIST\' directory first, then the subsequent 'TEMP' directory is created okay. The help files indicate that the subdirectories will be created to complete the path...
Okay so the directory now exists. I create a file using file_open('\CDLIST\TEMP\test.txt', 3), which works fine. I then close the file... No dramas.
2. The file_delete('\CDLIST\TEMP\*.*') function returns -5 (disk I/O error). Try as I might, I can not seem to be able to delete the file. I noticed that file_delete() works fine if the target file is not in any subdirectory.
3. The all-dangerous file_removedir('\CDLIST\TEMP\') also has no effect. Another -5 (disk I/O error)
Am I missing something, or is there an issue with the way directories are dealt with? There is plenty of space on the CF. There doesn't appear to be an equivalent command to change the current working directory, to allow me to use relative path names.
I think the help files & NetLinx Programming Language pdf could be a little bit more descriptive in this area. It probably warrants a seperate chapter to the topic.
NLS v2.3, NI-3000 running v2.31.137
Yours,
Roger McLean.
0
Comments
The help files claim that wild cards work (& multi-dir-depth file paths), but it certainly doesn't seem to in my case either. I guess there is a bug either in the file calls or in the associated documentation. I don't yet know how to post an official bug report, so I hope someone from AMX reads this. I'm sure they will... In the mean time, I'm off to manually remove all those files which I thought would have been deleted by now.
Roger McLean
and file delete does usually work fine. i'd say there is a good chance that the file has not been closed.
check the following..
after rebooting, without doing any file creation.. can you delete the file you want to get rid of ? it should be easily removed if it is not being held open elsewhere (maybe even try deleting it from FTP).
then...
create the file once. then try to create it again, after you believe you've closed it. check the result code.
as for the full path, i seem to recall netlinx will create the full path when you try to create the file. i haven't revisited that area since i've set it up in my core application and left it to deal with those issues.
i hope that helps.
In the original post if the current directory wasn't root I think both 2 and 3 would happen.
I've heard too that there are some modules by AMX that weren't rigourous with their file operations and leave the current directory in unexpected states.
Problem #1. Initially, there are no dirs created. The following test tells me that, contrary to the help file, file_createdir() will NOT create the number of subdirs needed to complete the path. I have to create each dir myself.
Problem #2 The file_removedir() will only work if there are no files or subdirs remaining in the dirpath. This is contrary to the help file, which states that all files & subdirectories contained within the directory will also be deleted. It will only work if there is nothing contained in the specified directory.
Problem #3. Wildcards do not seem work, contrary to the help file description of file_delete(). The only way I can see to clear out a directory is to first get the listing, then iterate through the listing deleting each file individually. (I have not yet tried that approach though.)
To ensure that my file ('\CDLIST\TEMP\test.txt') was always closed for these tests, I create it as follows: No other reading or writing to the file, just creating it (0 bytes long). theResult is of type SLONG, declared in the DEFINE_VARIABLE section.
Can someone please confirm (or refute) my observations. I believe that I am using the functions as they were intended, but that they are not performing as they should.
Oh, and I also missed the file_setdir(). Probably due to the mix of UPPER & lower case in the help file. The rest of the file functions are listed in UPPER case only. Thanks for pointing that one out.
Yours,
Roger McLean.