I'm writing to files on another system which have either a .ERR or .OK extension. What I want to do is be able to remove these files but I can only do it by way of using the exact file name; I'd like to be able to use a wildcard (*.ERR or *.OK) to remove all of the files with those extensions.
Apparently SYS_REMOVEFILE will not accept anything but the full file name.
Anyone have any ideas on how to accomplish removing files via the 'wildcard + extension' method??
I know in the downloads sections, there are libraries of code that may have this.
I have an implementation in my library, but I'm away from work and don't have all my dependencies with me.
What you basically want to do is the following pseudocode:
1) Get directory contents of the dir you are interested in (returned as a LIST OF FILEINFO, but all you care about is the .sName field of the FILEINFO record)
2) Use MatchStr and walk the list of FILEINFO, .sName field. looking for names that match your criteria, MatchStr takes wild cards
3) For each match, call down to SYS_RemoveFile. I suggest using do <--> except blocks with any FILEIO SilkTest code, just to be more bulletproof.
If you are still stuck I'll see if I have time in my busy work schedule to scrape together my implementation. May be a pain if you are not used to using SilkTest records. I use records as it makes it easy for me to add new functionality that I did not think of when I code something, as compared to a long list of single arguments...
EDIT: You could also use a wrapper to the command.com (or cmd.exe on NT) del command, with the appropriate syntax. If you use SYS_Execute, you may get more than you bargained for with some strange hangs etc... I prefer my method above with the walking lists of FILEINFO.
[This message has been edited by styler (edited 01-21-2001).]
Try this function:[-] DeleteSelectedFiles(STRING sDir)
[ ] LIST OF FILEINFO lfInputFiles
[ ] INTEGER iFCount
[ ] STRING sFileName
[ ] BOOLEAN bFnd
[ ] lfInputFiles = SYS_GETDIRCONTENTS(sDir) //Sets up a list of the files within the specified directory
[-] for iFCount = 1 to ListCount(lfInputFiles) //For each file in the list of files
[ ] sFileName = lfInputFiles[iFCount].sName //Get the name of the current file
[ ] bFnd = MatchStr("*.to", sFileName) //Match to see if the file contains the .to file extension
[-] if bFnd == TRUE
[ ] SYS_RemoveFile (sDir + sFileName)
The input to this function is the path of the files you want to check.
Hope this helps,
[This message has been edited by MikeF (edited 02-05-2001).]