PDA

View Full Version : File.Move etc



rhosk
01-31-2004, 01:46 PM
Have a small dilemma. I'm doing a File.Move (actually allowing the user to save a file to a different location) with this code -

function savefile()
file = Dialog.FileBrowse(false, "Save your file", _DesktopFolder, "All Files (*.*)|*.*|", "*.exe", "exe", false, true);
if (file[1] ~= "CANCEL") then
File.Move(_SourceDrive.."\\originalfile.exe", file[1], false, false, true, true, nil);
else
cancel = Dialog.Message("Cancelled?", "Are you sure you want to cancel?", MB_YESNO, MB_ICONQUESTION, MB_DEFBUTTON1);
if (cancel == IDYES) then
return
else
savefile();
end
end
end

The function and all works perfect, except if they saved a file previously as "myfile.exe" and they decide to name the file "myfile.exe" again, it doesn't ask to over-write. Is there a way I can prompt the user "are you sure you want to overwrite this file"? Currently, it just overwrites the file with no prompts.

TJ_Tigger
01-31-2004, 07:20 PM
You could use the Overwrite option in the File.Move function to prevent the file from being over written.

I don't know how exactly, but you might also add a File.DoesExist action to your code to check and see if the file name already exists and if no the write the file, if yes then prompt the user.

rhosk
02-01-2004, 03:39 AM
Originally posted by TJ_Tigger
You could use the Overwrite option in the File.Move function to prevent the file from being over written.

Nah, doesn't work. If you look at the File.Move action and highlight overwrite option, it gives you - Whether to overwrite any files in the destination folder if they have the same name as the files being moved

This doesn't help, it will still overwrite an "existing" file of any name - silently. I somehow need to take what they type in the dialog and compare it to the file being overwritten (if the case), but how in the heck can I do that?

TJ_Tigger
02-01-2004, 07:36 AM
fexist = File.DoesExist(file[1]);
if (fexist) then
qresult = Dialog.Message("Warning","You are about to overwrite an existing file. \r\n Do you want to continue?", MB_YESNO, MB_ICONQUESTION, MB_DEFBUTTON2);
if (qresult == IDYES) then
File.Move(_SourceDrive.."\\originalfile.exe", file[1], false, false, true, true, nil);
else
--allow them to enter a new name for the file here
end
end


What if you do something like to following. Fun a quick File.DoesExist to see if the file they want to use already exists and if it does prompt them to overwrite or not. Or you could pull the windows trick and add "Copy X" to the front of the file name before you save it.

I have not tested the code in AMS just worked with it here so it may need some massaging.

Tigg

rhosk
02-01-2004, 08:15 AM
That worked!! Now I need to somehow insert my cancel dialog :D

I'm getting lost with all the if's and else's and ends. I think I just need a break - time for coffee :o

Thanks again Tigg! If you ever need any help <long pause> .......um, I won't be able to do it......maybe someday!