View Full Version : Questions about searching all fixed drives for a file
mercury049
03-23-2006, 01:23 PM
Hi,
I've been reading in the forums a bit and managed to find some snippets to assist me in my task. I'm trying to make a little exe that will:
1. Find all fixed drives.
2. search all fixed drives that were found for a single file.
3. Overwrite that found file with a new one.
I'm trying the file.find , but I don't kno what folder this file is going to be stored in. The user could've put it anywhere. From the snippets, I've managed the following code :
drivetbl = Drive.Enumerate();
for drvindex, drives in drivetbl do
drive_type = Drive.GetType(drives);
if (drive_type == 3) then
appdirectory = File.Find(,"blah.exe",true,false,nil,nil);
if (appdirectory ~= nil) then
result = Dialog.Message("Notice", "" .. appdirectory[1], MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
break;
end
end
end
I know where I've left off is all messed up, but I don't know where to go from here. Any Help?
Thanks :huh
mercury049
03-23-2006, 01:44 PM
By the way I forgot when I listed that code I had taken out the drive to search for. So I've put back in and listed it below. I know it's wrong, but it's what I'm aiming for.
drivetbl = Drive.Enumerate();
for drvindex, drives in drivetbl do
drive_type = Drive.GetType(drives);
if (drive_type == 3) then
appdirectory = File.Find(drive_type,"blah.exe",true,false,nil,nil);
if (appdirectory ~= nil) then
result = Dialog.Message("Notice", "" .. appdirectory[1], MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
break;
end
end
end
I have the dialog message there just because I'm trying to see what the value would return and see when I get it right..which so far has proven difficult. :-) Thanks
Where you've left off, you have a table containing the locations of your file on the last drive searched...
replacement = "\\AutoPlay\\Docs\\myNewFile.ext";
drivetbl = Drive.Enumerate();
for drvindex, drives in drivetbl do
drive_type = Drive.GetType(drives);
if (drive_type == 3) then
appdirectory = File.Find(drives,"blah.exe",true,false,nil,nil);
if (appdirectory ~= nil) then
result = Dialog.Message("Notice", "" .. appdirectory[1], MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
for index, filename in appdirectory do
File.Install(replacement, filename, 2, true);
end
endend end
What we did here was add a File.Install() action into the loop so that as the search of each drive is complete, we replace any files found.
mercury049
03-23-2006, 02:44 PM
After tinkering a bit, I got the find to work and find the file. I used the following.
tbDrives = Drive.Enumerate();
for i,v in tbDrives do
if Drive.GetType(v) == DRIVE_FIXED then
tbFile = File.Find(v, "blah.exe", true, false, nil, nil);
if not tbFile then
else
File.Delete(""..tbFile[1], false, false, false, nil);
result = Dialog.Message("Notice", ""..tbFile[1], MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
break
end
end
end
Now the only problem is that the file I want to replace it with will be within the archive of the installer. I'm not quite sure how to pull that out and put in this files place.
I went to the install directory screen and set the directory to tbFile[1] , but it doesn't like that at all. This is going to be a download install and not from CD btw..so I don't know how I'd use _source. I know I'm completely wrong on this, any more help?
Thanks
mercury049
03-23-2006, 02:54 PM
TJS
I sure am glad you're seeing my messages, because you were the one that helped the last guy with something similar to this and you're where I found that first bit of code. I tried what you put in, but I still can't figure out how to point the replacement file to a file in the archive directory.
Thanks
you should be able to add the file in question to the "Primer" files for the project and distribute them outside of the installer (maybe zip them together for download)... or you could leave the file replace operation until after the install is performed. That way the file you need will be extracted and available.
mercury049
03-23-2006, 04:20 PM
Ok, so here's what I have so far.
I decided to do like you said and install the file first to a temp directory ("C:\blahupdater") then as an action on "POST INSTALL" have do what I'm trying to do, but I keep getting an error saying "Invalid Source" What am I missing?
replacement = "C:\BlahUpdater\blah2.exe";
drivetbl = Drive.Enumerate();
for drvindex, drives in drivetbl do
drive_type = Drive.GetType(drives);
if (drive_type == 3) then
appdirectory = File.Find(drives,"blah.exe",true,false,nil,nil);
if (appdirectory ~= nil) then
result = Dialog.Message("Notice", "" .. appdirectory[1], MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
for index, filename in appdirectory do
success = File.Install(replacement, filename, FILE_INSTALL_ALWAYS, false, false, nil, nil );
error = Application.GetLastError();
if success == false then
Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
end
end
end
end
end
Thanks for all the help by the way. I sure hope we get this figured out.
mercury049
03-24-2006, 09:07 AM
Anyone else have any ideas on what I can do to make this work?
Thanks
Jason Pate
03-24-2006, 01:19 PM
If I under stand your post you find your files now you want to replace it with a file in your setup. In the install path for this file I would set a special "session variable" then when I find the file in PRE install, I simply use "String.SplitPath" and to set the session variable to that location, just make sure you select a good over right option, aka set it to always over right if that’s what you are needing. Good Luck
path_Table = String.SplitPath(FOUNDFILE)
SessionVar.Set("%INSTALLMYFILE%", path_Table.Drive..path_Table.Folder)
I keep getting an error saying "Invalid Source" What am I missing?
hmmmm... Invalid Source generally means that the source file does not exist.... maybe double check that the source path and filename exactly match the place your installer is putting the executable.
Here's another thought... check the properties of actual file you are updating to... the code we have written is designed to find every instance of your .exe on the fixed drives and replace them with............. the one you just placed on the fixed drive........ lol. I wonder if the error you are getting is coming from the installer trying to replace a file with itself?
mercury049
03-24-2006, 03:30 PM
That's a thought. But to rule that out I set it to blah2.exe instead of just blah.exe So it's replacing blah.exe with blah2.exe . Just for testing. But you make a fine point. When I actually run this, how'm I gonna get this to work. The post from Jason Pate seems like a good idea. I'm going to try it here in a bit and I'll post later tonight to let you all know how it goes.
See, the thing is, in the end I just want it to take the files in the archive and overwrite or add to the directory's they belong in. The only problem is I need to find out where the user installed the software to begin with. I'm now wishing I would've had that stored in the registry, but it's too late now. Any other ideas?
Jeff
Jason Pate
03-24-2006, 04:48 PM
Yes I have done that before, and used my Idea and it works fine your just dynamically setting the appfolder during install time, if you have problem with it, let me know you can usually reach me online with MSN ID in my profile, or you can drop me an email. Good Luck. I can almost see the code if I close my eyes :)
mercury, I think the code you have is finding the target files just fine. It seems that the issue is with finding the source file.
Is this the format you are using to declare the source file location?
replacement = "C:\BlahUpdater\blah2.exe";drivetbl = Drive.Enumerate();
for drvindex, drives in drivetbl do
drive_type = Drive.GetType(drives);
if (drive_type == 3) then
appdirectory = File.Find(drives,"blah.exe",true,false,nil,nil);
if (appdirectory ~= nil) then
result = Dialog.Message("Notice", "" .. appdirectory[1], MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
for index, filename in appdirectory do
success = File.Install(replacement, filename, FILE_INSTALL_ALWAYS, false, false, nil, nil );
error = Application.GetLastError();
if success == false then
Dialog.Message("Error", _tblErrorMessages[error], MB_OK, MB_ICONEXCLAMATION);
end
end
end
end
end
If so, try this instead:
replacement = "C:\\BlahUpdater\\blah2.exe";
I'm now wishing I would've had that stored in the registry
PS Don't forget to write that to the registry this time around.
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.