Announcement

Collapse
No announcement yet.

File Copy with log file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • File Copy with log file

    Hi,

    I'm trying to copy files and folder from one location to other and provide a log file of files copied. The copy code works fine, just not sure how to get it to a text file. Can someone point me in the right direction? Thanks

    Code:
    StatusDlg.Show(MB_ICONNONE, false);
    --copy = File.Copy("E:\\genesis\\backups\\*.*", "Z:\\backup\\genesis", true, true, false, true, nil);
    
    -- Check to see if the File.Copy action failed by getting it's error code.
    error = Application.GetLastError();
    StatusDlg.Hide();
    
    -- If it failed (not equal to 0), display a dialog informing the user.
    if error ~= 0 then
        result = Dialog.Message("Error", "There was an error backing up the files. Please try again.", MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1);
    else
        Dialog.TimedMessage("Notice", "Files Copied.", 5000, MB_ICONINFORMATION);
    end

  • #2
    You can use a CallbackFunction - the last of the arguments passed to File.Copy() - to retrieve the info about which files are being copied, and write this into a text file for logging purposes.

    Ulrich

    Comment


    • #3
      Ulrich im not sure I follow. How do I do a callback?

      Comment


      • #4
        It is documented in the help file.

        Ulrich

        Comment


        • #5
          Hi,

          Still trying to work out this callback function. Below is what I have some what figured out. I get a "Error: attempt to index global 'arg' (a nil value)."
          Any suggestions? Thanks

          Code:
          function callfunction(Source, Destination, Copied, Total, FileCopied, FileTotal)
          	
             local nFilePer  = Math.Round(arg[5] * 100 / arg[6]);
             local nTotalPer = Math.Round(arg[3] * 100 / arg[4]);
              
            Progress.SetCurrentPos("Progress1", nFilePer);
            Progress.SetCurrentPos("Progress2", nTotalPer);
            Label.SetText("Label4", Copied);
            TextFile.WriteFromString("C:\\Backup_log.txt", Copied, false);
             
          end
          
          File.Copy("C:\\ACTS\\*.*", "C:\\ACTS2\\", true, true, false, true, callfunction);

          Comment

          Working...
          X