by
nimbi63 » Tue Jan 21, 2014 6:53 pm
I wrote this on many years ago, but it should still work.
name copy_txt
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! Retrieve destination directory if passed on command line !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
parameter copy_dir$ default "C:\LABWKS\HPDATA"
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! Declare variables local to this macro !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
local file_name$ ! Current .TXT file name in data file subdirectory
local new_file$ ! New file name for .TXT file
local retvar ! Generic function return variable
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! If destination directory and REPORT.TXT file found - copy!!
!! REPORT.TXT to destination directory as <Data File>.TXT - !!
!! else write error message to current LOGBOOK !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
If FILESTAT(MODE,copy_dir$) > 0 then !! Destination Directory Found
file_name$ = DADataPath$ + DADataFile$ + "\REPORT.TXT"
If FileStat(MODE,file_name$) > 0 Then !! REPORT.TXT File Found
new_file$ = copy_dir$ + "\" + DADataFile$[1:Len(DADataFile$)-1] + "TXT"
copy file_name$,new_file$,DONTASK
Print "Copied File '" + file_name$ + "' to '" + new_file$+"'"
WriteToLogbook "COPY_TXT: Copy Successful"
Else !! REPORT.TXT File NOT Found
WriteToLogbook "COPY_TXT: REPORT.TXT Not Found"
EndIf
Else !! Destination Directory Not Found
WriteToLogbook "COPY_TXT: Destination Path Not Found"
EndIf
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! Return control to system !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
return
endmacro
!-----------------------------------------------------------------
name COPY_TXT_HOOK
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! Check for current view = DA (Data Analysis). If so, add !!
!! 'User Macros' menu choices to Data Analysis view !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
If TabHdrText$(_Config,"Window","CurrentView") = "DA" Then
MenuAdd "User Macros","Copy TXT File","COPY_TXT",,\
"Copy TXT File To Other Destination"
Print "Custom Rpts menu added"
EndIf
EndMacro
!----------------------------------------------------------------------
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! INSTALLATION macro to create and/or append commands to load !!
!! macro COPY_TXT.MAC in USER.MAC file. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
name Install_COPY_TXT
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! Append Macro commands to file USER.MAC to !!
!! add automatic loading of macro COPY_TXT !!
!! during Chemstation initialization !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Open _EXEPATH$ + "USER.MAC" for append as #101
Print #101, ""
Print #101, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Print #101, "!! Section Added By COPY_TXT.MAC !!"
Print #101, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Print #101, "Macro "+Chr$(34)+"COPY_TXT.MAC"+Chr$(34)
Print #101, "SETHOOK "+Chr$(34)+"PostDA"+Chr$(34)+","\
+Chr$(34)+"COPY_TXT"+Chr$(34)
Print #101, "SETHOOK "+Chr$(34)+"PreViewMenu"+Chr$(34)+","\
+Chr$(34)+"COPY_TXT_HOOK"+Chr$(34)
Print #101, "Remove Install_COPY_TXT"
Print #101, "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
Close #101
Print "COPY_TXT.MAC commands added to USER.MAC"
EndMacro