PDA

View Full Version : Newbie file.copy problem


FloridaJohnnyG
03-22-2009, 02:22 PM
AutoPlay Media Studio 7.5

I am trying to copy a file from "AutoPlay\\Docs\\testmsg1.txt to a folder in C:\Program Files\Application X\TestFolder.

Wow! What I thought would be trivial is driving me crazy.

I wrote this script:
File.Copy("AutoPlay\\Docs\\testmsg1.txt", _ProgramFilesFolder .. "\\Application X\TestFolder");
error = Application.GetLastError();
if )error ~= 0) then
Dialog.Message("Error", _tbleErrorMeesages [error], MB_OKCANCEL, MB_ICONEXCLAMATION);
else
File.ExploreFolder(_ProgramFilesFolder .. "\\Application X\TestFolder");
end

I can create a folder in C: but not anthing in the Program Files especially in a nested subdirector within Program Files.

I am running Windows Vista.

All help is sincerely appreciated.:)

Imagine Programming
03-22-2009, 02:37 PM
File.Copy("AutoPlay\\Docs\\testmsg1.txt", _ProgramFilesFolder .. "\\Application X\\TestFolder");
error = Application.GetLastError();
if )error ~= 0) then
Dialog.Message("Error", _tbleErrorMeesages [error], MB_OKCANCEL, MB_ICONEXCLAMATION);
else
File.ExploreFolder(_ProgramFilesFolder .. "\\Application X\\TestFolder");
end

You forgot to escape the last folder path's part. (See red highlighted slashes) add those and it should work (If those folders exist)

FloridaJohnnyG
03-22-2009, 02:51 PM
Thank you for the speedy reply.

It was my error in copying the script. I did have the \\ in the correct places and am getting an error message "Failed to copy one or more files.

Again, all help is greatly appreciated.

Imagine Programming
03-22-2009, 04:18 PM
Ah i remember, File.Copy somehow doesn't accept "Autoplay\\Docs\\bla.txt" so try:


File.Copy(_SourceFolder.."\\".."AutoPlay\\Docs\\testmsg1.txt", _ProgramFilesFolder .. "\\Application X\\TestFolder");
error = Application.GetLastError();
if (error ~= 0) then
Dialog.Message("Error", _tbleErrorMeesages [error], MB_OKCANCEL, MB_ICONEXCLAMATION);
else
File.ExploreFolder(_ProgramFilesFolder .. "\\Application X\\TestFolder");
end

mwreyf1
03-22-2009, 06:30 PM
How do you manage to mess up the code with copy and paste?

MISTAKES EVERYWHERE

Try this...

File.Copy("AutoPlay\\Docs\\testmsg1.txt", _ProgramFilesFolder .. "\\Application X\\TestFolder");
error = Application.GetLastError();

if (error ~= 0) then
Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
else
File.ExploreFolder(_ProgramFilesFolder .. "\\Application X\\TestFolder");
end


Remember, if the folder doesn't exist it will not copy the file but you will get the "_tblErrorMessages" message explaining such.

FloridaJohnnyG
03-22-2009, 06:36 PM
Again, thank you for your suggestion. Unfortunately it didn't work either.

My belief is that this may be a permission's problem as I can write to other directories but not Program Files.

Strange. I'm really stumped as I have to copy a file to a specific directory or the application I developed will not work properly.

Dermot
03-22-2009, 07:11 PM
If you are using Vista, you can't copy files to Program Files like that.

Desrat
03-22-2009, 07:41 PM
Autoplay Menu > Project > Settings > Advanced > Requested User Privilege Level (Vista) > Require Administrator > Click Ok

FloridaJohnnyG
03-22-2009, 07:55 PM
It definitely was a permissions problem. Thanks for pointing me in the correct direction. Although in my case I was not able to change the settings in the Requested User Privilege Level as it was greyed out.

I solved the problem by turning off the User Account Control.

Although it worked, I was wondering why my options are greyed out (not available).