Reserve words used in string cause problems renaming file

Good day only my 3rd time in 25 years to use this kind of help.
I am using c5.5 h and do the following without knowing to be a problem.

I have 2 string variable -fromfile and tofile these variable gets filled with a drive file path and filename.
I use command Rename to copy fromfile to tofile.

Because of the directory called break it breaks loop 2 into loop 1 without renaming. It is not a word standing alone it is inside a string.
Comme4nt is there more such reserve word not to use so i can exclude them to be used by users???

Here is source code:

fromfile = f:\source\fromfile.pdf  
tofile = c:\data\break\tofile.pdf - variable2
loop1
   conditions to break loop 1
   loop 2
     other conditions to chek file string is correct and if not it breaks
     rename(fromfile,tofile)
  end
end

If you post the actual source code we may be able to help.

  1. I found the problem but do not know why and then I may build a database with problematic reserved words:

  2. If the companycode in line 2 is “break” a reserved word, than the RENAME or COPY DO NOT WORK.

Thanks for answering.

SOURCECODE

!Chk Exist folder for Company
if sub(clip(PRN:StmPDFolder),-1,1) <> '\' then PRN:StmPDFolder = CLIP(PRN:StmPDFolder) & '\'.
SubFolderName = clip(PRN:StmPDFolder) & CLIP(COM:CompanyCode)
if~ exists(SubFolderName)
If~ MkDir(SubFolderName)
!then message('NOT exist,Will create')
end
end
if sub(clip(PRN:OthPDFolder),-1,1) <> '\' then PRN:OthPDFolder = CLIP(PRN:OthPDFolder) & '\'.
fromfile =clip(PRN:OthPDFolder) & 'Prnstatementblank.pdf'
if exists(fromfile) then remove(fromfile).

tofile = clip(SubFolderName) & '\' & format(today(),@d12) & '-'& CLIP(COM:CompanyName) & '.pdf'
RepGLO:CompCode = COM:CompanyCode
Prnstatementblank
! MESSAGE('AFT PRN|' & fromfile & '|' & tofile)
Loop3 LOOP
IF EXISTS(TOFILE)
BREAK Loop3
end
LoopTime = CLOCK()
Loop4 LOOP
IF EXISTS(FROMFILE) THEN BREAK loop4.
IF (CLOCK() - LoopTime) > 6000
MESSAGE('Can not find file to rename|' & CLIP(FROMFILE))
BREAK loop4
END
END !end loop 4
rename(fromfile,tofile)
END !end loop 3

LoopTime = clock()
!check if rename worked.
loop
if~ exists(Tofile)
if clock() - LoopTime > 1000
If Message('The file:-' & clip(Fromfile) & '|Did not copy to:- ' & clip(Tofile) & '|Please investigate and report if problem persist.',,ICON:Question,'&Retry|&Abort',1,0) = 1
rename(fromfile,ToFile)
LoopTime = clock()
CYCLE
else !ABORT RENAME
BREAK
end
end
else !TOFILE EXIST
IF DELFILE = 1 then remove(fromfile).
break
end
end !end loop exist or warning done

wow That’s convoluted code, May I suggest…

  1. you should use COPY to transfer a file from one folder or drive to another, RENAME won’t work
  2. does a simple MESSAGE display the source/destination filenames correctly at the point whereby you want the action to happen?

To figure things out you should check for an Error after the Copy or Rename:

rename(fromfile,ToFile)
IF ErrorCode() THEN
   Message('Rename failed with Error: '& ErrorCode() &' '& Error() & |
           '||From File: ' & clip(Fromfile) & |
           '|To File: ' & clip(Tofile) & |
           '||Please investigate and report if problem persist.',,ICON:Question,....

I also would suggest using COPY rather than RENAME.

Good Morning Gents,

Firstly thanks for all the help, especially the error issue. I always used error(0 to do fault finding, but for some reason I drifted away from it.
The error WAS access denied. I eventually found it was the filename containing illegal characters.
Thanks for all the help.

I use below Err4Msg() function to easily get all the error functions info in a Message(). Also for a log file or debug passing (1).

  MAP
Err4Msg  PROCEDURE(Byte NoCRLF=0),STRING  !Fromat ErrorCode() & Error() & FileError... for Message() Stop() Halt() or Log file (NoCRLF)
  END
!-----------------------------------------
Err4Msg  PROCEDURE(Byte NoCRLF=0)!,STRING 
  !Example: IF ERRORCODE() THEN STOP('Failed ADD(xxx)' & Err4Msg()).
  !Note: Return starts '<13,10><13,10>Error Code:' so no need to put in the Message()
  CODE
  IF ~ERRORCODE() THEN RETURN ''.   
  IF ~NoCRLF THEN 
     RETURN '<13,10><13,10>Error Code: ' & ERRORCODE()&' '&ERROR() & |
             CHOOSE(~FILEERRORCODE(),'','<13,10>Driver Error: ' & FILEERRORCODE()&' '&FILEERROR() ) & | 
             CHOOSE(~ERRORFILE(),'','<13,10>File Name: ' & ERRORFILE() )
  END 
  !NoCRLF<>0 is 1 line format for use by logging
  RETURN ERRORCODE()&' '&ERROR() & |     ! {148}
         CHOOSE(~FILEERRORCODE(),'',' [Driver ' & FILEERRORCODE()&' '&FILEERROR() &']' ) & | 
         CHOOSE(~ERRORFILE(),'',' {{' & ERRORFILE() & '}' ) 

So with your code:

rename(fromfile,ToFile)
IF ErrorCode() THEN
   Message('Rename failed. Please investigate and report if problem persists.' & |
           '||From File: ' & clip(Fromfile) & |
           '|To File: ' & clip(Tofile) & |
           Err4Msg() ,,ICON:Question,....

This would show a message like below where the last like is the output of Err4Msg():

=================================================================
Rename failed. 
Please investigate and report if problem persists.

From File: f:\source\Prnstatementblank.pdf
To File: c:\data\break\Prnstatementblank.pdf

Error Code: 5 Access Denied
=================================================================
3 Likes