Copy a folder

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Teqskater
    Forum Member
    • Apr 2007
    • 175

    Copy a folder

    Is there an easy way to copy a folder and all its contents?
  • jassing
    Indigo Rose Customer
    • Jan 2001
    • 3124

    #2
    Originally posted by Teqskater View Post
    Is there an easy way to copy a folder and all its contents?
    yes.

    Code:
    File.Copy(SourceFolder.."\*.*",destinationFolder,true,true,false,true,nil);

    Comment

    • Teqskater
      Forum Member
      • Apr 2007
      • 175

      #3
      i've tried this: File.Copy("AutoPlay\\Adv Duplicator\\*.*", "C:\\Documents and Settings\\Teqskater\\Bureaublad\\Copy", true, true, false, true, nil);

      And it didnt work. It has also subfolders with files Btw

      Comment

      • jassing
        Indigo Rose Customer
        • Jan 2001
        • 3124

        #4
        Originally posted by Teqskater View Post
        i've tried this: File.Copy("AutoPlay\\Adv Duplicator\\*.*", "C:\\Documents and Settings\\Teqskater\\Bureaublad\\Copy", true, true, false, true, nil);

        And it didnt work. It has also subfolders with files Btw
        did you check the Application.GetLastError()?

        I would add _SourceFolder to it to be sure.

        Comment

        • Teqskater
          Forum Member
          • Apr 2007
          • 175

          #5
          Now i tryed this code: First a message to check if it is realy the correct path.
          and it is. then a statusdialog pops up en goes away in a blink. then no error is displayed. it just doesnt want to copy. the folder has files and subfolders with files. this should be easy but its an issue i have often.

          Code:
          result = Dialog.Message("Notice", _SourceFolder.."AutoPlay\\Adv Duplicator", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
          
          StatusDlg.Show(MB_ICONNONE, false);
          File.Copy(_SourceFolder.."\\AutoPlay\\Adv Duplicator\\*.*", "C:\\Documents and Settings\\Teqskater\\Bureaublad\\Copy", true, true, false, true, nil);
          StatusDlg.Hide();
          
          -- Test for error
          error = Application.GetLastError();
          if (error ~= 0) then
          	Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
          end
          I think i need to write a separate function for it.

          Comment

          • jassing
            Indigo Rose Customer
            • Jan 2001
            • 3124

            #6
            do you check for the folders existance? Showing it doesn't indicate if it exists or not.

            Comment

            • Teqskater
              Forum Member
              • Apr 2007
              • 175

              #7
              yes i did that multiple times. anyways. thanks for helping me.
              when it shows up i can see if the path is correct thats wy i used dailog.message

              Comment

              • RizlaUK
                Indigo Rose Customer
                • May 2006
                • 5552

                #8
                try this

                Code:
                result = Dialog.Message("Notice", _SourceFolder.."[COLOR="Red"]\\[/COLOR]AutoPlay\\Adv Duplicator", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
                
                StatusDlg.Show(MB_ICONNONE, false);
                File.Copy(_SourceFolder.."\\AutoPlay\\Adv Duplicator\\*.*", "C:\\Documents and Settings\\Teqskater\\Bureaublad\\Copy", true, true, false, true, nil);
                StatusDlg.Hide();
                
                -- Test for error
                error = Application.GetLastError();
                if (error ~= 0) then
                	Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
                end
                Embrace change in your life, you never know, it could all work out for the best

                Comment

                • jassing
                  Indigo Rose Customer
                  • Jan 2001
                  • 3124

                  #9
                  Originally posted by Teqskater View Post
                  yes i did that multiple times. anyways. thanks for helping me.
                  when it shows up i can see if the path is correct thats wy i used dailog.message
                  OK -- but the code you posted doesn't show that you check for it's existance....

                  Good luck on your issue -- please let us know what you discover.

                  -josh

                  Comment

                  • Teqskater
                    Forum Member
                    • Apr 2007
                    • 175

                    #10
                    i'll sure do. But actualy i think its a bug.
                    I gonna make a workaround function to copy a folder and all his contents.
                    Ill post it here when im done.

                    Comment

                    • Teqskater
                      Forum Member
                      • Apr 2007
                      • 175

                      #11
                      This is my workaround function:

                      Code:
                      --[[	
                      Explanation:
                       Copy's a folder with al his contents to another location
                      Arguments:
                       from: The source directory to copy from (string)
                       to: The destination directory to copy to (string)
                       ov: overwrite files if a duplicate has bin found (boolean)
                       ab: abort on copy error (boolean)
                       hid: include hidden files (boolean)
                       dlg: show a statusdialog or not (boolean)  
                      Created by teqskater
                      ]]    
                      function CopyFolder(from, to, ov, ab, hid, dlg)
                      local folders = Folder.Find(from, "*", true, nil);
                      local files = File.Find(from, "*", true, false, nil, nil);
                      	-- initialize statusdialog
                      	local nfolders = Table.Count(folders);
                      	local nfiles = Table.Count(files);
                      	local length = nfolders + nfiles;
                      	StatusDlg.SetMeterRange(0, length);
                      	-- get folders inside the "from" folder only
                      	for i, v in folders do
                      		folders[i] = String.Replace(folders[i], from, "", true);
                      	end
                      	
                      	-- get files inside the "from" folder only
                      	for i, v in files do
                      		files[i] = String.Replace(files[i], from, "", true);
                      	end
                      	
                      	-- show statusdialog
                      	if dlg == true then
                      		StatusDlg.Show(MB_ICONNONE, false);
                      	end
                      	-- create folders into "to" path
                      	for i,v in folders do
                      		Folder.Create(to..folders[i]);
                      	end
                      	
                      	-- create files into "to" path
                      	for i,v in files do
                      		File.Copy(from..files[i], to..files[i], true, ov, ab, hid)
                      	end
                      	-- hide statusdialog
                      	if dlg == true then
                      	StatusDlg.Hide();
                      	end
                      end
                      Example:
                      Code:
                      CopyFolder(_SourceFolder.."\\AutoPlay\\My source folder", _DesktopFolder.."\\My Destination Folder", true, false, true, false);
                      Enjoy! :yes :lol

                      If you find a bug please post here and i will fix it. I tested the function and ith works for me.
                      I was much quicker done then i tought . I'm getting pro in AMS. haha.
                      Last edited by Teqskater; 04-02-2008, 09:54 PM.

                      Comment

                      • Worm
                        Indigo Rose Customer
                        • Jul 2002
                        • 3971

                        #12
                        You can try this method too.

                        Comment

                        • Teqskater
                          Forum Member
                          • Apr 2007
                          • 175

                          #13
                          Darn. That i didnt see that earlyer. Thanks Worm! :yes

                          Comment

                          Working...
                          X