Please do post your comments and suggestions for me to improve on chowdary1105@gmail.com

Sunday, August 9, 2009

File operations using DOS commands in SQR

We can use the following as an sqc, for performing file operations in SQR.

!*********************************************************************
!Program Name : FileOprs.sqc
!Description : File operations using DOS commands.
!*********************************************************************

!*********************************************************************
!Procedure Name : Make_Dir
!Description : Creates a new path based on the input. Path must be
! a complete directory tree listing.
!Usage : Do Make_Dir($Directory_NewPath)
!*********************************************************************
begin-procedure Make_Dir($NewPath)
#debugy show ‘In Procedure : Make_Dir’

Let $Commmand_line = ‘cmd /c mkdir ‘ || $NewPath
Do Exec_Cmd($Commmand_line)

end-procedure ! Make_Dir

!*********************************************************************
!Procedure Name : Exec_Cmd
!Description : Executes $Commmand_line on the system and reports
! errors for debugging.
!Usage : Do Exec_Cmd($Commmand_line)
!*********************************************************************
begin-procedure Exec_Cmd($Commmand_line)
#debugy show ‘In Procedure : Exec_Cmd’

call system using $Commmand_line #status nowait
If #status <> 0
#debugy show ‘Command ‘ $Commmand_line ‘ failed to execute.’
End-If

end-procedure ! Exec_Cmd

!*********************************************************************
!Procedure Name : Copy_Files
!Description : Copy files from old to new path. Old information should be of
! form \pathname\filename, while new information can just be a path.
!Usage : Do Copy_Files($old_file_name, $new_file_name)
!*********************************************************************
begin-procedure Copy_Files($old, $new)
#debugy show ‘In Procedure : Copy_Files’

Let $Commmand_line = ‘cmd /c copy ‘ || $old || ‘ ‘ || $new
Do Exec_Cmd($Commmand_line)

end-procedure ! Copy_Files

!*********************************************************************
!Procedure Name : Move_Files
!Description : Move files from old to new path. Old information should be of
! form \pathname\filename, while new information can just be a path.
!Usage : Do Move_Files($old_file_name, $new_file_name)
!*********************************************************************
begin-procedure Move_Files($old, $new)
#debugy show ‘In Procedure : Move_Files’

Let $Commmand_line = ‘cmd /c move ‘ || $old || ‘ ‘ || $new
Do Exec_Cmd($Commmand_line)

end-procedure ! Move_Files

!*********************************************************************
!Procedure Name : Delete_Files
!Description : Deletes the files passed in variable $files
!Usage : Do Delete_Files($files)
!*********************************************************************
begin-procedure Delete_Files($files)
#debugy show ‘In Procedure : Delete_Files’

Let $Commmand_line = ‘cmd /c del ‘ || $files
Do Exec_Cmd($Commmand_line)

end-procedure ! Delete_Files

No comments: