PeopleCode to Archive files from Inbound folder to Archive Folder.

&Filename is File Name.

FILE_INPUT: To get input file path for the file name &Filename.

FILE_INPUT_ARCH: To get Archive file path for the files.

Global string &Filename;

&filetype = “FILE_INPUT”;
SQLExec(“SELECT A.FILE_DIRECTORY FROM PS_AE_FILE_DIR A WHERE A.NAME1 = :1”, &filetype, &file_path);
&filetypearch = “FILE_INPUT_ARCH”;
SQLExec(“SELECT A.FILE_DIRECTORY FROM PS_AE_FILE_DIR A WHERE A.NAME1 = :1”, &filetypearch, &arch_path);

MessageBox(0, “”, 0, 0, “Action : Archive”);
If FileExists(&file_path | &Filename, %FilePath_Absolute) Then
   &Str = “gzip ” | &file_path | &Filename;
   &exitcode1 = Exec(&Str, %Exec_Asynchronous + %FilePath_Absolute);
   If &exitcode1 = – 1 Then
      MessageBox(0, “”, 0, 0, &Filename | ” has been compressed “);
   Else
      MessageBox(0, “”, 0, 0, “ERROR: ” | &Filename | ” File compress failed. “);
      &strErr = “ERROR: ” | &Filename | ” File compress failed. “;
      Error &strErr;
   End-If;
   &gzip_file = &file_path | &Filename | “.gz”;
   &Str_cmd = “mv ” | &gzip_file | ” ” | &arch_path | &Filename | “-” | %Datetime | “.gz”;
   &exitcode = Exec(&Str_cmd, %Exec_Asynchronous + %FilePath_Absolute);
   If &exitcode = – 1 Then
      MessageBox(0, “”, 0, 0, &Filename | ” has been archived in ” | &arch_path);
   Else
      MessageBox(0, “”, 0, 0, “ERROR: ” | &Filename | ” File archive failed. “);
      &strErr = “ERROR: ” | &Filename | ” File archive failed. “;
      Error &strErr;
   End-If;
Else
   MessageBox(0, “”, 0, 0, “ERROR: ” | &Filename | ” File not found in: ” | &file_path);
   &strErr = “ERROR: ” | &Filename | ” File not found in: ” | &file_path;
   Error &strErr;
End-If;

Advertisements