I’m trying to use an event routine to check a directory for any text files over 4kb. If it finds a file matching that description I want to move and rename the file with the date as part of the name. I keep running into “Can’t Rename File”
I have this code in the user.sys module set to trigger with an Event RESET:
VAR String Date;
VAR iodev logfile;
VAR dir directory;
VAR string filename;
PROC rSaveAndClearEvent()<-------This is the routine triggered by the event RESET
rSearchDir “HOME:/TEMPDATA”,“rSaveAndClear”;
ENDPROC
PROC rSearchDir(string dirname, string actionproc)<-------Which Proc Calls this
IF IsFile(dirname \Directory) THEN
OpenDir directory, dirname;
WHILE ReadDir(directory, filename) DO
! .. and . is the parent and resp. this directory
IF filename <> “..” AND filename <> “.” THEN
rSearchDir dirname+“/”+filename, actionproc;
ENDIF
ENDWHILE
CloseDir directory;
ELSE
%actionproc% dirname;
ENDIF
ERROR
RAISE;
ENDPROC
PROC rSaveAndClear(string filename)
IF FileSize(filename) > 4096 THEN
Date:=CDate();
RenameFile filename, “Home:/ERRORDATA/”+Date+filename;<-----I know this is the line of code giving me the problems.
Open filename, logfile\write; Right now, ‘filename’ contains the entire path Home:/TEMPDATA/******.txt
Write logfile, " "; Is there a way to pull out just the actual filename and use it in the RenameFile?
Close logfile; If I only use “Home:/ERRORDATA/”+Date; The rest of the code works, but only gives me the date and on
ENDIF the next file I get an error that I already have a file with that name (obvious, but I wanted to demonstrate
RETURN; everything else is working)
ENDPROC