Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2003
    Posts
    5

    Help Please - Find & Rename - Noob

    Project:
    To install an application and find on hard drive files and rename extension for unnecessary files. I need to do full search for TestFile1.dll and TestFile2.dll. When found rename files to TestFile1.dl and TestFile2.dl. If files are not found to display error message. These file can reside on either C: or D: so I would need to search multiple drives.

    I can have it rename files at the known drive letter and folder(C:\Blah) but I would like for the script to "FIND"(search C: D: E: ) incase it isn't the default folder.
    I managed to search C:\ drive and when not found error message came up but when found files it would not rename(script error) with this example:

    result = File.Find("WindowsRoot=String.Left(_WindowsFolder, 3)", "TestFile1.dll", true, true, nil);
    if result == nil then
    Message = file not found
    else
    Rename =
    end
    (adapted from TJTigger in forums)

    Can anyone help, almost giving up.

  2. #2
    Join Date
    Jul 2003
    Posts
    712
    Hello Grim,

    The following example may be what you are looking for.

    Please keep in mind, searching the user's hard drive like this takes a LONG time. You may want to be more specific of where you are searching for the files, and turn the recursion option off.


    Code:
    -- The drives to search through, in format c:\\
    tDrivesToSearch = {"C:\\", "D:\\"};
    
    -- The files to search for
    tFilesToSearchFor = {"TestFile1.dll", "TestFile2.dll"};
    
    --traverse through the drive table
    for nIndex, sDrive in tDrivesToSearch do
    	
    	-- traverse through the file table
    	for nIndex, sFile in tFilesToSearchFor do
    		
    		--search for the specified file on the specified drive
    		tFoundFiles = File.Find(sDrive, sFile, true, false, nil);
    		
    		-- if files were found:
    		if tFoundFiles then
    			-- traverse through the found files table
    			for nIndex, sFile in tFoundFiles do
    				-- Rename files from *.dll to *.dl
    				File.Rename(sFile, String.TrimLeft(sFile, "dll") .. "dl");
    			end
    		else
    			-- File was not found, display error message
    			Dialog.Message("Error", "File '" .. sFile .. "' was not found on your system.", MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1);
    		end
    	end
    end

  3. #3
    Join Date
    Dec 2003
    Posts
    5
    You're correct, failed to realize that one.

    Do I change this line:
    tDrivesToSearch = {"C:\\", "D:\\"};
    "C:\\" to {"C:\program files", "D:\programs files"} ?

    Changed Error = string.TrimLeft to String.TrimRight)

    BTW - with script above, files are renamed from TestFile.dll to TestFile.dl sucessfully, however message "Error Files Not Found" still pops up even after files were found and renamed. It looks like "end" function after File.Rename is not working properly. What's your suggestion?



    Thank you very much for your response, really. This is about the deepest in script I have ever been.

  4. #4
    Join Date
    Jul 2003
    Posts
    712
    Good Morning!

    You're right, TrimLeft should have been TrimRight. My bad!
    With regards to the error message popping up . . . please see the below code. I failed to take into account that unless every file in the table was found on every drive/location listed, the error would pop up. What i've done is as soon as at least one file is found, i set a boolean variable to true. At the end, the error message only displays if this value is set to false (not true).

    Hope that works for ya!

    Code:
    -- The drives to search through, in format c:\\
    tDrivesToSearch = {"C:\\", "D:\\"};
    
    -- The files to search for
    tFilesToSearchFor = {"TestFile1.dll", "TestFile2.dll"};
    
    -- Used to control error message at the end
    bFound = false;
    
    --traverse through the drive table
    for nIndex, sDrive in tDrivesToSearch do
    	
    	-- traverse through the file table
    	for nIndex, sFile in tFilesToSearchFor do
    		
    		--search for the specified file on the specified drive
    		tFoundFiles = File.Find(sDrive, sFile, true, false, nil);
    		
    		-- if files were found:
    		if tFoundFiles then
    			-- Keep track that at least this file was found
    			bFound = true;
    
    			-- traverse through the found files table
    			for nIndex, sFile in tFoundFiles do
    				-- Rename files from *.dll to *.dl
    				File.Rename(sFile, String.TrimRight(sFile, "dll") .. "dl");
    			end
    		end
    	end
    end
    
    if not bFound then
    	-- File was not found, display error message
    	Dialog.Message("Error", "File '" .. sFile .. "' was not found on your system.", MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1);
    end

  5. #5
    Join Date
    Dec 2003
    Posts
    5
    Stumbled in to this message:
    Error
    "On Click, Line 35: attemp to concatenate global 'sFile'(a nil value)

    Referring to this line:

    33 if not bFound then
    34 -- File was not found, display error message
    35 Dialog.Message("Error", "File '" .. sFile .. "' was not found on your system.", MB_OK, MB_ICONEXCLAMATION, MB_DEFBUTTON1);
    end

    What I did was changed messsage to say "Error - TestFile1.dll and TestFile2.dll were not found on your system, please check they exist or reinstall Application!" Which makes ALL work perfect. I'll try and learn more APMS scripting more and see if I can get the proper solution (practice project).

    I really thank you for your assistance. As a plus I added your name "Desmond" to the Credits screen under "Created with APMS 5.0" Assistance by "Desmond" Indigorose Forums.

    Let me know if you want me to change anything from above.

  6. #6
    Corey is offline Indigo Rose Staff Alumni
    Join Date
    Aug 2002
    Posts
    9,746
    First the grammy for male bassoonist of the year, now this. Desmond's name is really getting out there...

    Corey Milner
    Creative Director, Indigo Rose Software

  7. #7
    Join Date
    Jul 2003
    Posts
    712
    Sorry Grim, I shoulda tested that before I posted. The variable sFile only exists within the for loop. You were 100% correct with your change. Good show!

    Sorry dude! And thanks for the credits. That's really cool!

Similar Threads

  1. How would I find a blank line of text via "Find Text Line"?
    By Marker0077 in forum Setup Factory 6.0
    Replies: 11
    Last Post: 07-11-2003, 08:55 AM
  2. Replies: 2
    Last Post: 01-13-2003, 01:00 AM
  3. Find and replace within a file
    By HayoOellrich in forum Setup Factory 6.0
    Replies: 1
    Last Post: 10-31-2002, 02:19 PM
  4. Update can't find Folders
    By Khanh in forum AutoPlay Menu Studio 3.0
    Replies: 6
    Last Post: 03-10-2002, 02:44 PM
  5. Where To Find More....
    By dsgbknuckleup in forum AutoPlay Menu Studio 3.0
    Replies: 1
    Last Post: 07-09-2001, 08:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts