trap an error on movefile
Moderators: JRL, Dorian (MJT support)
trap an error on movefile
I want to move a file from folder a to folder b. Movefile> does work, but if the file is open, the file doesn't move and the macro doesn't pause or abbend. all well and good but I want to trap the return code from movefile>
If the move was successful, log the file name.
If the move was unsuccessful, do not log the file.
How do I do this?
I tried
If>(Movefile>%filename%,%Dir%)
WriteLn>%logfile%,filename
EndIf
but the WriteLn executes if the file is not moved.
If the move was successful, log the file name.
If the move was unsuccessful, do not log the file.
How do I do this?
I tried
If>(Movefile>%filename%,%Dir%)
WriteLn>%logfile%,filename
EndIf
but the WriteLn executes if the file is not moved.
Michael Clark
try this
Code: Select all
Let>Dir=c:\temp\
Let>NewDir=c:\temp\NewFolder\
Let>LogFile=c:\temp\Log.txt
Let>FileName=myfile.txt
Let>NewFileName=myfile.bak
IfWindowOpen>%Dir%%filename%,END,NEXT
Label>NEXT
Movefile>%Dir%%fileName%,%NewDir%%NewFileName%
WriteLn>%LogFile%,%FileName%
Label>END
Aaron
Aaron's method may work for you, but it assumes the file name is in WindowName.
What sort of file are you moving? Text?
If it is text, why not
ReadFile>OldFile,TheFileText
Writeln>NewFile,result,TheFileText
then, possibly try to delete OldFile?
Many possibilities, but it depends on the type of file with which you are dealing.
What sort of file are you moving? Text?
If it is text, why not
ReadFile>OldFile,TheFileText
Writeln>NewFile,result,TheFileText
then, possibly try to delete OldFile?
Many possibilities, but it depends on the type of file with which you are dealing.
Unfortunately this doesn't work in this situation. I'm not sure if the cause is the file being opened by another user on a different workstation it's a network file, or the name of the file inside the loop.
I have the process and logging part in a loop
Repeat>k
Let>k=k+1
IfWindowOpen>file_names_%k%,END,NEXT
Label>NEXT
MoveFile>file_names_%k%,%StageDir%
WriteLn>%LogFile%,%file_names_%k%
Label>END
Until>k,file_names_count
file_names_%k% has the full path and file name in it. The open PDF has just the file name in the window header. Any ideas how to strip out the path part of file_named_%k%?
I have the process and logging part in a loop
Repeat>k
Let>k=k+1
IfWindowOpen>file_names_%k%,END,NEXT
Label>NEXT
MoveFile>file_names_%k%,%StageDir%
WriteLn>%LogFile%,%file_names_%k%
Label>END
Until>k,file_names_count
file_names_%k% has the full path and file name in it. The open PDF has just the file name in the window header. Any ideas how to strip out the path part of file_named_%k%?
Michael Clark
let>PathAndFile=file_names_%k%
seperate>%PathAndFile%,\,segment
let>TheFile=Segment_%segment_count%
IfWindowOpen>*%TheFile%*,END,DoIt
Label>DoIt
MoveFile>file_names_%k%,%StageDir%
WriteLn>%LogFile%,%file_names_%k%
Label>END
EndIf
Until>k,file_names_count
Isolates the file name and if the application with the open the file is on the local workstation the above logic works. If it's a file on the network and the file is opened by the application on another workstation, this doesn't work. IfWindowOpen is local. It's not a true OS filesystem handle check.
darn, so close.
seperate>%PathAndFile%,\,segment
let>TheFile=Segment_%segment_count%
IfWindowOpen>*%TheFile%*,END,DoIt
Label>DoIt
MoveFile>file_names_%k%,%StageDir%
WriteLn>%LogFile%,%file_names_%k%
Label>END
EndIf
Until>k,file_names_count
Isolates the file name and if the application with the open the file is on the local workstation the above logic works. If it's a file on the network and the file is opened by the application on another workstation, this doesn't work. IfWindowOpen is local. It's not a true OS filesystem handle check.
darn, so close.
Michael Clark
Let me state this more clearly. If you are working with networked files that may be opened by other networked computers, no variation of IfWindowOpen> is going to help you detect that a file on the network is open and therefore cannot be moved.
What will work is to move the file using MoveFile> then check the new location for the existance of the supposedly moved file using IfFileExists>. If the move was successful the new file will exist. If the move was unsuccessful because the file is in use by another workstation, the new file will not exist. Going back to your originally posted code sample, you had the right idea, just the wrong syntax.
If>(Movefile>%filename%,%Dir%)
WriteLn>%logfile%,filename
EndIf
It needs to be rewritten like this:
MoveFile>%filename%,%Dir%
IfFileExists>%Dir%
WriteLn>%logfile%,%filename%
Else
//Do something else
EndIf
What will work is to move the file using MoveFile> then check the new location for the existance of the supposedly moved file using IfFileExists>. If the move was successful the new file will exist. If the move was unsuccessful because the file is in use by another workstation, the new file will not exist. Going back to your originally posted code sample, you had the right idea, just the wrong syntax.
If>(Movefile>%filename%,%Dir%)
WriteLn>%logfile%,filename
EndIf
It needs to be rewritten like this:
MoveFile>%filename%,%Dir%
IfFileExists>%Dir%
WriteLn>%logfile%,%filename%
Else
//Do something else
EndIf