Announcement

Collapse
No announcement yet.

File Not Moving

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

  • File Not Moving

    Im having an issue with being unable to move a file. Perhaps a fresh set of eyes may be able to point out if i am missing something:

    Code:
    -- Determine if there is a claims.mpn file to be backed up
    found = File.DoesExist(_SourceFolder .. "\\claims.mpn");
    
    -- If file found, backup to OldClaims folder otherwise alert user no file to backup
    if found == true then
    
     -- Determine if there is an OldClaims folder, if not, create it
     claimsfolder = Folder.DoesExist(_SourceFolder .. "\\OldClaims");
     
     if claimsfolder ~= true then
      Folder.Create(_SourceFolder .. "\\OldClaims");
     end
     
     -- Set variables for current date and time
     cdate = System.GetDate(DATE_FMT_US);
     ctime = System.GetTime(TIME_FMT_AMPM);
      
     File.Move(_SourceFolder .. "\\claims.mpn", _SourceFolder .. "\\OldClaims\\claims_" ..cdate.. "_" ..ctime.. ".txt", false, true, false, false, nil);
     
     Dialog.Message("Finished", "Your claims file has been backed up.", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
     
    else
     
     Dialog.Message("Error", "No claims file to backup", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
    
    end
    I get the dialog that the the file was backed up, but the file remains in the source folder and there is nothing in the OldClaims folder.
    Matt Leach
    GalacTek Corp.
    www.galactek.com

  • #2
    You have some issues in your code. Replace it with this, and check how it performs:
    Code:
    -- Determine if there is a claims.mpn file to be backed up
    if File.DoesExist(_SourceFolder .. "\\claims.mpn") then
        -- If file found, backup to OldClaims folder otherwise alert user no file to backup
        
        if not Folder.DoesExist(_SourceFolder .. "\\OldClaims") then
            -- Determine if there is an OldClaims folder, if not, create it
             Folder.Create(_SourceFolder .. "\\OldClaims");
            error = Application.GetLastError();
            if (error ~= 0) then
                Dialog.Message("Folder.Create()", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
                Application.ExitScript();
            end
        end
     
         -- Set variables for current date and time
         cdate = String.Replace(System.GetDate(DATE_FMT_US), "/", "_");
         ctime = String.Replace(System.GetTime(TIME_FMT_AMPM), ":", "_");
      
         File.Move(_SourceFolder .. "\\claims.mpn", _SourceFolder .. "\\OldClaims\\claims_" ..cdate.. "_" ..ctime.. ".txt", false, true, false, false, nil);
        error = Application.GetLastError();
        if (error ~= 0) then
            Dialog.Message("File.Move()", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
        else
                Dialog.Message("Finished", "Your claims file has been backed up.", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
            end
    else
        Dialog.Message("Error", "No claims file to backup", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
    end
    Note that you are not performing error checking, so I have inserted a couple of tests.

    Also, you may know that you cannot use any character in a filename on Windows. Colons and slashes cannot be used, so a filename like this is invalid, which is what you are generating in your code:

    Code:
    D:\sourcefolder\OldClaims\claims_09/13/2017_11:23:31 PM.txt
    In my changed script, I replace the prohibited characters, rewriting the file name as this:

    Code:
    D:\sourcefolder\OldClaims\claims_09_13_2017_11_23_48 PM.txt
    I believe that this will work much better.

    Ulrich

    Comment


    • #3
      I didnt even think of the date or time having invalid characters for the filename, totally overlooked that fact!!

      As always, thank you very much for the assistance, it is greatly appreciated!
      Matt Leach
      GalacTek Corp.
      www.galactek.com

      Comment

      Working...
      X