PDA

View Full Version : Copy EVERYTHING please



Bruce
08-20-2005, 12:53 PM
I'm trying to copy all the files from my project CD to the user’s hard drive. This is the code I am using:

==ON CLICK==
--get the destination folder
sDestFolder = Dialog.FolderBrowse("Select the Destination Folder", _DesktopFolder)
--see if the user cancelled
if sDestFolder ~= "CANCEL" then
--initiate the copy
--CopyFolder is function in the Global Functions area of the project (Alt-D-F)
if CopyFolder(_SourceFolder, sDestFolder) == 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
end



==GLOBAL==
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


Not all the files want to be copied including the AutoPlay.exe :huh

longedge
08-20-2005, 01:59 PM
I know it's not an answer Bruce but how about creating a seperate zip of your whole app and putting that in docs - unzip instead of copying.

I wonder, could the problem be something to do with file locking even though the files are on CD?

Bruce
08-20-2005, 02:11 PM
Hey longedge-
Good idea I didn't think of that. Problem is, every CD is a little different. Each CD is dynamically produced so the time needed to zip everyone would be a pain.

I'll take a look at the locking idea, thanks

longedge
08-20-2005, 02:19 PM
Just another thought that's only relevant if the dynamic part of your distribution is not in the executable.

You could have a generic zip file with the files that don't copy properly and then do as you do now with the dynamic files.

TJ_Tigger
08-21-2005, 10:47 AM
Will copy a file if it is in use? Could that be stopping the copy function?

Eagle
08-24-2005, 08:10 AM
Bruce ..try this 'Root path fix' (common issue if wanting to duplicate from the
'root' of a source ..CD or Hardisk.

replace below line:

if CopyFolder(_SourceFolder, sDestFolder) == 0 then

with:


_SourceFolder = String.Mid(_SourceFolder, 1, 2).."\\"; --Source is now set for Root of CD
if CopyFolder(_SourceFolder, sDestFolder) == 0 then


HTH

(normally files 'in use' can still be copied)

Eagle
08-24-2005, 08:28 AM
Note: for non NT type Oss..drop the "\\" (is appended in the copy func anyway) and use:

_SourceFolder = String.Mid(_SourceFolder, 1, 2);

Bruce
08-25-2005, 01:05 AM
Thanks Eagle I'll try it out. :D