Announcement

Collapse
No announcement yet.

Folder Does Exist, File Copy code check please

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

  • Folder Does Exist, File Copy code check please

    Hi All
    Can someone check my code please
    I want to add a folder and a file if exist's.
    The code below Creates a folder but don't copy the file to that folder, the folder is empty.

    The GameList.db file is located at Autoplay Docs.


    Code:
    if Folder.DoesExist("C:\\My Games") then
      File.Copy("\\AutoPlay\\Docs\\GameList.db", "C:\\My Games", true, true, false, true, nil);
    else
     Folder.Create("C:\\My Games");
    end

  • #2
    "\\AutoPlay\\Docs\\GameList.db" should be "AutoPlay\\Docs\\GameList.db" but do use application get last error as it would tell you the file does not exist.

    Comment


    • #3
      Thanks Shrek
      Is this how it goes for the application get last error
      because it creates the folder but no file added

      Code:
      -- Check to see if a specific folder exists.
      if Folder.DoesExist("C:\\My Games") then
        File.Copy("\\AutoPlay\\Docs\\GameList.db", "C:\\My Games", true, true, false, true, nil);
      else
       Folder.Create("C:\\My Games");
      end
      
      
      --Check to see if an error occurred.
      error = Application.GetLastError();
      
      -- If an error occurred, display the error message.
      if (error ~= 0) then
          Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
      end

      Comment


      • #4
        Code:
        -- Check to see if a specific folder exists.
        if Folder.DoesExist("C:\\My Games") then
          File.Copy("AutoPlay\\Docs\\GameList.db", "C:\\My Games", true, true, false, true, nil);
          local err = Application.GetLastError()
          if (err ~= 0) then
            Dialog.Message("Error", _tblErrorMessages[err].."\r\n".."AutoPlay\\Docs\\GameList.db", MB_OK, MB_ICONEXCLAMATION);
          end
        else
         Folder.Create("C:\\My Games");
        end
        try the _SourceFolder variable instead if that don't work.

        Comment


        • #5
          Also make a check the file is in the folder before coping
          Plugins or Sources MokoX
          BunnyHop Here

          Comment


          • #6
            Hi All
            Thanks for the help

            This has now been fixed. I used this code

            Code:
            if not Folder.DoesExist("C:\\My Games")then
              Folder.Create("C:\\My Games");
            end
            File.Copy("\\AutoPlay\\Docs\\GameList.db", "C:\\My Games", true, true, false, true, nil);

            Comment

            Working...
            X