Here is the code...
Sample Call: Copies the content of D:\ to C:\Program Files\My App
Global Function
Sample Call: Copies the content of D:\ to C:\Program Files\My App
Code:
if CopyFolder("D:\\", "C:\\Program Files\\My App") == 0 then result = Dialog.Message("Folder Copy", "The folder has been successfully copied!", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1); else result = Dialog.Message("Folder Copy", "There was an error copying the folder.", MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1); end
Code:
function CopyFolder(sSource, sDestination) local m_sFolder; local m_FoundFolder; local error; --Find all the folders and sub-Folders --results are stored in the table m_tblFolders m_tblFolders = Folder.Find(sSource, "*", true, nil); --if our destination folder does not have the --backslash as the last character, add it if String.Right(sDestination, 1) ~= "\\" then sDestination = sDestination .. "\\"; end --m_tblFolders will be nil if there are no folders if m_tblFolders ~= nil then --enumerate through the found folders for n, m_FoundFolder in m_tblFolders do --replace the source's path with the destination's path m_sFolder = String.Replace(m_FoundFolder, sSource, sDestination, false); --create the folder Folder.Create(m_sFolder); error = Application.GetLastError(); if (error ~= 0) then --set n to value to exit FOR loop n = Table.Count(m_tblFolders) end end end --if no errors occurred, copy the files if (error == 0) then --show the status dialog StatusDlg.Show(MB_ICONNONE, false); --copy all files from the source folder, with recurse. File.Copy(sSource .. "\\*.*", sDestination, true, true, false, true, nil); --hide the status dialog StatusDlg.Hide(); error = Application.GetLastError(); end --clean up m_tblFolders = nil; return error; end
Comment