PDA

View Full Version : Patch



Armanyes
04-12-2006, 07:45 AM
What is the code for finding a file and paste another file beside it ?

Wonderboy
04-12-2006, 08:31 AM
You mean you want to search for a file, example "my file.txt" and see if this file is found and when this file is found you want to place another file into the same folder as where this file is at?

Wonderboy
04-12-2006, 08:37 AM
Try this code, this code searches for a file called TestFile on all hard drives,
and ones this file is found it checks to see if the file is in use and if the size in bytes of the file is equel to what i wanted it to be,and if it is it will be replaced with a file from the docs folder, witch is in a ziped file, you could use this and make some small changes to it,

function DoIfFileFound(sFile)
--check to see if the file is in use if not then proceed with the check
if not File.IsInUse(sFile) then
-- Check the file size, this will need to be customized for your application
if File.GetSize(sFile) == 40 then
--if it is a match then you can ask your question about overwritting.
result = Dialog.Message("Overwrite", "Do you want to overwrite the file:\r\n"..sFile, MB_YESNO, MB_ICONQUESTION, MB_DEFBUTTON1);
if result == IDYES then
local tbSplit = String.SplitPath(sFile);
Zip.Extract("AutoPlay\\Docs\\file.zip", {"*.*"}, tbSplit.Drive..tbSplit.Folder, false, false, "", ZIP_OVERWRITE_ALWAYS, nil);
nErr = Application.GetLastError()
if nErr ~= 0 then
Dialog.Message("Error", "There was an error replacing the file \r\n\r\n"..sFile.."\r\n\r\nThe error was ".._tblErrorMessages[nErr]);
else
Dialog.Message("Success", "The file was successfully replaced");
File.Delete("AutoPlay\\Docs\\Dummyfolder\\DummyFile.txt", false, false, false, nil);
end
return false;
else
--set to true to continue search
return false;
end
else
--set to true to continue searching.
return false;
end
end
end

--This code executes the find
--find all the drives present in the system
tbDrives = Drive.Enumerate();
for i,v in tbDrives do
--if the drive is a fixed hard drive then look for the file
if Drive.GetType(v) == DRIVE_FIXED then
-- if the file is found this line will execute the DoIfFileFound function which is described above.
tbFile = File.Find(v, "*TestFile*.*", true, false, nil, DoIfFileFound);
if not tbFile then
bNotFound = true
end
end
end

if bNotFound then
file_exist = File.DoesExist("AutoPlay\\Docs\\Dummyfolder\\DummyFile.txt", false, false, false, nil);
if file_exist == true then
result = Dialog.Message("File not found", "the file was not found.", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
else
end
end

This nice code was provided to me by one of the great members on this forum, TJ_Tigger, and with some smal changes by myself so that it would fit me needs

Armanyes
04-12-2006, 09:35 AM
First of all thank you very much for your code , then i want to it search for a file for example (winRAR.exe) to find out where it installed . after that paste my file for example (reg.txt) to the same folder .