PDA

View Full Version : Interesting Problem



PreDr.ag
03-21-2007, 11:48 AM
I have two (I think interesting) questions:

First - how to write script that search a file and if that file isnt on that partition search another etc.Also I need to copy a file from application to that one.And last I need dialog message to notify user that file is or isnt found
and when file is copied.

Because I don know almost anything about writing script dont laugh at my
attempt to write this one
*problem is that first dialog shows and then second dialog show that file was copied but it isnt*

Dialog.Message ("Please wait","File is being copying")
result = File.Find("C:\\", "file.something", true, nil);
if (result) then
strnew = Table.Concat(result, "", 1, TABLE_ALL);
File.Copy("AutoPlay\\Docs\\file2.something", strnew, true, true, false, true, nil);
Dialog.Message ("File is copied","OK")
else -- if file isnt found search another partition
result1 = File.Find("D:\\", "file.something", true, nil);
if (result1) then
strnew1 = Table.Concat(result1, "", 1, TABLE_ALL);
File.Copy("AutoPlay\\Docs\\file2.something",strnew1, true, true, false, true, nil);
Dialog.Message ("File is copied","OK")
else
result2 = File.Find("E:\\", "file.something", true, nil);
if (result2) then
strnew2 = Table.Concat(result2, "", 1, TABLE_ALL);
File.Copy("AutoPlay\\Docs\\file2.something", strnew2, true, true, false, true, nil);
Dialog.Message ("File is copied","OK")
else
Dialog.Message ("Error","File isnt found")
end
end
end

PreDr.ag
03-21-2007, 12:59 PM
How to make file browse for user to select a specific file (file.something) an copy another in that path.Also if selected file isnt file.something then Dialog.message to notify that selected file isnt file.something.

TJS
03-21-2007, 01:15 PM
Here's a project to get you started. This shows how to take a user entered filename and search all drives attached to the user's computer for that file.

All of the important code is on the "Search Now" button ("Button1").

Keep in mind that the File.Find() action in AMS returns a table of all files matching the search criteria. You should be prepared that the user's system might have more than one file matching the search. Maybe you want just copy the first on found or maybe you want to copy all of them. If you want the later, you'll need to decide how you want to prevent overwriting (because they might all have the same name).

TJS
03-21-2007, 01:22 PM
Here's another example using your code...



--Dialog.Message ("Please wait","File is being copying")
drives = Drive.Enumerate();


for index, driveLetter in drives do

StatusDlg.Show();
result = File.Find(driveLetter, "file.something", true, false);
StatusDlg.Hide();

if (result) then

File.Copy(result[1], "AutoPlay\\Docs\\", true, true, false, true, nil);

Dialog.Message("File is copied","OK");

else

Dialog.Message("Error","File isn't found on " .. driveLetter);

end

end


I added the StatusDlg actions so the user has something to see with the search occurs.

RizlaUK
03-21-2007, 01:31 PM
ok, heres some code for both your dilemers

this will search all drives on the system, when the file is found the user will be asked if thay want to copy the new file

it uses a callback function to dispaly the status dialog

function Found (filename)
Copy = Dialog.Message("FOUND!!", filename .. " was found!!\r\nWould you like to copy file . . .", MB_YESNO);
if Copy == IDYES then
Path = String.SplitPath(filename);
File.Copy("AutoPlay\\Docs\\File2.txt", Path.Drive.."\\"..Path.Folder, true, true, false, true, nil);

error = Application.GetLastError();
if (error ~= 0) then
Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
else
Dialog.Message("Error", "File Copy OK", MB_OK, MB_ICONEXCLAMATION);
end
end
return false;
end

Drives = Drive.Enumerate();
FileName = "File.txt"--change this to your filename
StatusDlg.Show();
for i,v in Drives do
File.Find(Drives[i], FileName, true, true, nil, Found);
end
StatusDlg.Hide();


this one will ask to fine the file, and compair it to the filename stored in the var "FileToLookFor", if it matches then user is asked if thay want to copy the new file


FileToLookFor = "myfile.txt"
selFile = Dialog.FileBrowse(true, "Locate File", _DesktopFolder, "All Files (*.*)|*.*|", "", "dat", false, false);
if selFile[1] ~="CANCEL" then
sPath = String.SplitPath(selFile[1]);
if sPath.Filename..sPath.Extension == FileToLookFor then
sCopy = Dialog.Message("Notice", "File matches, would you like to copy new file.", MB_YESNO, MB_ICONINFORMATION, MB_DEFBUTTON1);
if sCopy == IDYES then
File.Copy("AutoPlay\\Docs\\File2.txt", sPath.Drive.."\\"..sPath.Folder, true, true, false, true, nil);
error = Application.GetLastError();
if (error ~= 0) then
Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
else
Dialog.Message("Error", "File Copy OK", MB_OK, MB_ICONEXCLAMATION);
end
end
else
Dialog.Message("Error", "The file dose not match", MB_OK, MB_ICONEXCLAMATION);
end
end


EDIT:, lmao.....every time i work on code for someone im always to late with the reply :p