View Full Version : Simple questions from a newbie
Quantrac
02-15-2005, 01:47 PM
I am trying to copy files from my cd to the hard drive. Here is what I have so far:
result = Dialog.Message("Notice", "Would you like to install your customized company database?", MB_YESNO, MB_ICONINFORMATION, MB_DEFBUTTON1);
if (IDYES) then
File.Copy("Directmail & Attachments\\Attachments.dat", "C:\\Quantum\\Data\\", true, false, false, true, nil);
File.Copy("Directmail & Attachments\\directmail.mdb", "C:\\Quantum\\Data\\", true, true, false, true, nil);
File.Copy("Hvac\\Database\\HVAC01.DAT", "C:\\Quantum\\Data\\", true, false, false, true, nil);
end
result = Dialog.Message("Notice", "Database Files Installed Successfully.", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
I need for it the code to detect if all 3 files already exist and and not copy the ones that do exist and copy the ones that don't. Then give a dialog message that tells the user which files existed and that the system can not copy them. If none of the files exist then I would just like a dialog message that says "Database Files Installed Sucessfully".
Hope someone can help me with this.
Thank you guys.
AMy
Roboblue
02-15-2005, 02:25 PM
Is there a reason that you can't just set the filecopy for not overwrite. You wouldn't need a confirmation on the files that DO already exist.
makes a difference in the example I would give you.
Quantrac
02-15-2005, 02:30 PM
Using the filecopy to not overwrite would be ok. Thanks for your help. Its greatly appreciated.
Stefan_M
02-15-2005, 02:44 PM
Not the shortest one, but it should work.
t_file={}
t_file[1]="Directmail & Attachments\\Attachments.dat";
t_file[2]="Directmail & Attachments\\directmail.mdb";
t_file[3]="Hvac\\Database\\HVAC01.DAT";
OK=true;
Info="";
if (IDYES) then
for x,act in t_file do
actfile=String.SplitPath(act).Filename..String.Spl itPath(act).Extension;
if not File.DoesExist("C:\\Quantum\\Data\\"..actfile) then
--file doesn't exist -> copy
File.Copy("Directmail & Attachments\\"..actfile, "C:\\Quantum\\Data\\", true, false, false, true, nil);
else
Info=Info.."file ".."C:\\Quantum\\Data\\"..actfile.." exists and won't be copied.\r\n"
OK=false;
end;
end;
if OK then
result = Dialog.Message("Notice", "Database Files Installed Successfully.", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
else
result = Dialog.Message("Notice", Info, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
end;
end;
Stefan_M
Quantrac
02-15-2005, 02:52 PM
Stephan,
That works great! Except for one thing, it's not coping the HVAC01.DAT FILE, I can't figure it out.
Thanks,
Amy
Roboblue
02-15-2005, 02:53 PM
just a query to install, create the install folders (only if they don't already exist), file copy with no overwrite, and process complete confirmation. If the files are huge, then we can put in a progess dialog, also.
Stefan_M
02-15-2005, 02:59 PM
Sorry didn't testet it
t_file={}
t_file[1]="Directmail & Attachments\\Attachments.dat";
t_file[2]="Directmail & Attachments\\directmail.mdb";
t_file[3]="Hvac\\Database\\HVAC01.DAT";
OK=true;
Info="";
if (IDYES) then
for x,act in t_file do
actfile=String.SplitPath(act).Filename..String.Spl itPath(act).Extension;
if not File.DoesExist("C:\\Quantum\\Data\\"..actfile) then
--file doesn't exist -> copy
File.Copy(t_file[x], "C:\\Quantum\\Data\\", true, false, false, true, nil);
else
Info=Info.."file ".."C:\\Quantum\\Data\\"..actfile.." exists and won't be copied.\r\n"
OK=false;
end;
end;
if OK then
result = Dialog.Message("Notice", "Database Files Installed Successfully.", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
else
result = Dialog.Message("Notice", Info, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
end;
end;
change
File.Copy("Directmail & Attachments\\"..actfile, "C:\\Quantum\\Data\\", true, false, false, true, nil);
to
File.Copy(t_file[x], "C:\\Quantum\\Data\\", true, false, false, true, nil);
Stefan_M
Quantrac
02-15-2005, 03:04 PM
Thanks for all your help Stephan. This is not the first time you have helped me with some coding. I really appreciate it.
Amy ;)
Quantrac
02-15-2005, 04:54 PM
The code works great, but now when the files are copied they are copied as read only. My access database will not work with the attributes set as read only. Can you add to the code to change or set the file atttributes to uncheck the readonly option? Thanks a bunch!
Amy
Roboblue
02-15-2005, 05:26 PM
this will set the read only to false after the files are copied.
Quantrac
02-16-2005, 11:50 AM
I am using Stephan's code above and I need the file attributes worked into his code. I tried pasting yours, but it blew it up. Can you help me by adding it into his code. Thanks.
Amy
Derek
02-16-2005, 11:55 AM
Paste this in. You can paste it after Stefan's code if you wish.
attrib = File.GetAttributes("C:\\Quantum\\Data\\Attachments.dat");
attrib.ReadOnly = false;
File.SetAttributes("C:\\Quantum\\Data\\Attachments.dat", attrib);
If you need this on the other 2 files, simply create it again for the other 2 and change the filename
Stefan_M
02-16-2005, 12:02 PM
simply insert the function 'File.SetAttributes' after the File.Copy operation.
File.Copy(t_file[x], "C:\\Quantum\\Data\\", true, false, false, true, nil);
File.SetAttributes("C:\\Quantum\\Data\\"..actfile, ReadOnly=false);
Stefan_M
Derek
02-16-2005, 12:11 PM
Of course, i'm forgetting the attrib table is 'built-in'
Dont forget curly braces with that:
File.SetAttributes("C:\\Quantum\\Data\\"..actfile, {ReadOnly=false});
Stefan_M
02-16-2005, 12:17 PM
Shame on me.
To much copy and paste and no tests.
I'm going to stand in the corner for a while.
Stefan_M
Quantrac
02-16-2005, 12:23 PM
Thank you once again Stefan for helping me with this code. It's working perfectly! Thanks Derek for your last tip, I was getting a error and was getting ready to post until I got your post.
You guys have a good one.
Amy :yes ;)
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.