PDA

View Full Version : Copying My Documents


jcuster
09-26-2008, 10:55 AM
The story is I found some cool VB scripts that burn to CD or DVD. What I would like to do is have SUF use these scripts to burn a backup of the My Documents folder to a DVD(s) or CD(s).

What I'm having trouble with is getting My documents into a set of temp folders for burning.

Like Disk1, Disk2, Disk3.

The code that I'm currently using for another application that I would just like to modify is as follows;

function COPYCB(Source,Destination,Copied,Total)
DlgProgressBar.SetPos(CTRL_PROGRESS_BAR_02, (nfl / nflcnt) * 100);
return true; --continue copying
end

function copyfls(Srce,Dst,MDerror)
--set source and destination values, then 'find files' to table
g_FolderSize = 0;TCOPIED = 0;T_str = " ";

local Ssrce = Srce;
local Sdest = Dst;
local l25 = false
local l50 = false
local l75 = false
tfldrs = Folder.Find(Ssrce, "*", true, nil);
tfiles = {}
local tfiles = File.Find(Ssrce, "*.*", true, false, nil, OnFileFound);
if tfiles then
if (not Folder.DoesExist(Sdest)) then
Folder.Create(Sdest); --create Destination 'Parent Folder
end
if tfldrs then
LnSsrce = String.Length(Ssrce);
Allfldrs = Table.Count(tfldrs);
for x=1, Allfldrs do
tst = String.Mid(tfldrs[x], LnSsrce, -1);
tsttf = Folder.DoesExist(Sdest..tst);
if testtf ~= true then
Folder.Create(Sdest..tst);
end
end
end


local nlngth = String.Length(Ssrce); nflcnt = Table.Count(tfiles); destdir = {};

--cycle and copy each file , calling callback function named: COPYCB()
for n=1,nflcnt do
nfl = n; local dest = String.Mid(tfiles[n], nlngth +1, -1);
--note: it may be worth considering the File.Install action instead of file.copy
File.Copy(tfiles[n], Sdest..dest, true, true, true, true, COPYCB);
MDerror = Application.GetLastError();

--Jerry's Update Progress Bar
Pcnt = Math.Round((nfl / nflcnt * 100), 0)
if Pcnt == 25 and l25 == false then
DlgProgressBar.SetPos(CTRL_PROGRESS_BAR_01,(DlgPro gressBar.GetPos(CTRL_PROGRESS_BAR_01)+ 1));
l25 = true
end
if Pcnt == 50 and l50 == false then
DlgProgressBar.SetPos(CTRL_PROGRESS_BAR_01,(DlgPro gressBar.GetPos(CTRL_PROGRESS_BAR_01)+ 1));
l50 = true
end
if Pcnt == 75 and l75 == false then
DlgProgressBar.SetPos(CTRL_PROGRESS_BAR_01,(DlgPro gressBar.GetPos(CTRL_PROGRESS_BAR_01)+ 1));
l75 = true
end
gpos = DlgProgressBar.GetPos(CTRL_PROGRESS_BAR_01)
shrt = String.AbbreviateFilePath(tfiles[n], 72);
DlgStaticText.SetProperties(CTRL_STATICTEXT_LABEL_ 04,{Text = shrt.." "});
DlgProgressBar.SetProperties(CTRL_PROGRESS_BAR_02, {Text = Pcnt.."%"});
tpnct = Math.Round(gpos * 5,0)
if gpos == 0 then
DlgProgressBar.SetProperties(CTRL_PROGRESS_BAR_01, {Text = "0%"});
else
DlgProgressBar.SetProperties(CTRL_PROGRESS_BAR_01, {Text = tpnct.."%"});
end

end
end
nflcnt = nil; nfl = nil; --clear the two global values
end

PS. I think most of this code came from Jassing, thanks it works great for copying from entire location to another.

jassing
09-26-2008, 02:27 PM
so you want to copy "a folder" to "x# of folders" such that each 'x' folder is at most z megs?

It's definately doable -- the simple method is to keep a running total of each file that is copied; when the next file to be copied would go over Z; then you increment X and create a new folder; and reset the total count of bytes.

The tricky part would be to optimize the copy routine to maximize the space usage in each folder, such that you got as close to Z (w/o going over) as possible...

jcuster
09-27-2008, 01:00 PM
so you want to copy "a folder" to "x# of folders" such that each 'x' folder is at most z megs?

It's definately doable -- the simple method is to keep a running total of each file that is copied; when the next file to be copied would go over Z; then you increment X and create a new folder; and reset the total count of bytes.

The tricky part would be to optimize the copy routine to maximize the space usage in each folder, such that you got as close to Z (w/o going over) as possible...

Let me specify further. This routine Creates Folders seperatly from the copy routine.

Even before I get into the X and z portion I think I need to combine the "create Folder routine" and the "Copy files routine." I'm having a real bear of a time getting the tfldr and tfiles to match.

jassing
09-27-2008, 01:20 PM
I'm having a real bear of a time getting the tfldr and tfiles to match.

I'm not clear on what you're after then...sorry.

jcuster
09-27-2008, 08:32 PM
Let me explain more

This part of the funtcion creates the folders for the destination, Sdest

if tfldrs then
LnSsrce = String.Length(Ssrce);
Allfldrs = Table.Count(tfldrs);
for x=1, Allfldrs do
tst = String.Mid(tfldrs[x], LnSsrce, -1);
tsttf = Folder.DoesExist(Sdest..tst);
if testtf ~= true then
Folder.Create(Sdest..tst);
end
end
end

This part copies the files to folders in Sdest.



local nlngth = String.Length(Ssrce); nflcnt = Table.Count(tfiles); destdir = {};

--cycle and copy each file , calling callback function named: COPYCB()
for n=1,nflcnt do
nfl = n; local dest = String.Mid(tfiles[n], nlngth +1, -1);
--note: it may be worth considering the File.Install action instead of file.copy
File.Copy(tfiles[n], Sdest..dest, true, true, true, true, COPYCB);
MDerror = Application.GetLastError();

--Jerry's Update Progress Bar
Pcnt = Math.Round((nfl / nflcnt * 100), 0)
if Pcnt == 25 and l25 == false then
DlgProgressBar.SetPos(CTRL_PROGRESS_BAR_01,(DlgPro gressBar.GetPos(CTRL_PROGRESS_BAR_01)+ 1));
l25 = true
end
if Pcnt == 50 and l50 == false then
DlgProgressBar.SetPos(CTRL_PROGRESS_BAR_01,(DlgPro gressBar.GetPos(CTRL_PROGRESS_BAR_01)+ 1));
l50 = true
end
if Pcnt == 75 and l75 == false then
DlgProgressBar.SetPos(CTRL_PROGRESS_BAR_01,(DlgPro gressBar.GetPos(CTRL_PROGRESS_BAR_01)+ 1));
l75 = true
end
gpos = DlgProgressBar.GetPos(CTRL_PROGRESS_BAR_01)
shrt = String.AbbreviateFilePath(tfiles[n], 72);
DlgStaticText.SetProperties(CTRL_STATICTEXT_LABEL_ 04,{Text = shrt.." "});
DlgProgressBar.SetProperties(CTRL_PROGRESS_BAR_02, {Text = Pcnt.."%"});
tpnct = Math.Round(gpos * 5,0)
if gpos == 0 then
DlgProgressBar.SetProperties(CTRL_PROGRESS_BAR_01, {Text = "0%"});
else
DlgProgressBar.SetProperties(CTRL_PROGRESS_BAR_01, {Text = tpnct.."%"});
end

end
end
nflcnt = nil; nfl = nil; --clear the two global values
end

For instance I need to
1 Find the files
2 Get the file size
3 Increment the Size counter
4 Check the size counter against the disk size
5 Either increment the destination or keep it the same
6 (resetting the size counter if needed)

Now heres the tricky part the creation of the folders is separate from the copy file process

7 Create the folder
8 Copy the File
9 Repeat 2-8 until complete

Because of Step 7 and 8 I need to change the routine. Or did I misinterrupt the logic?

I think this routine can be modded to create the folder just before the file is copied but I'm not sure how?

jassing
09-27-2008, 08:39 PM
Or did I misinterrupt the logic?

well; I'm not sure -- but the obvious error is in your variables...

tsttf = Folder.DoesExist(Sdest..tst);
if testtf ~= true then

jcuster
09-30-2008, 10:39 AM
I had to use the following code to create folders with the files. I had to make one table with both empty folders and files. Next I had to Identify the folders with a trailing "\\", thus allowing me to identify it later and create the folders in the destination.


tfiles = {};tfldrs = {}

tfldrs = Folder.Find(Ssrce, "*", true, nil);
local tmptfiles = File.Find(Ssrce, "*.*", true, true, nil, OnFileFound);
for x,y in tfldrs do
Table.Insert(tfiles, Table.Count(tfiles)+1, y.."\\");
end
for x,y in tmptfiles do
Table.Insert(tfiles, Table.Count(tfiles)+1, y);
end
Table.Sort(tfiles, nil)




tst = String.Right(tfiles[n] ,1 );
if tst == "\\" then
Folder.Create(Sdest..dest)
end


Now I can work on changing the destination folder, if it gets to a certian size..