Indigo Rose Software

Professional Software Development Tools

 
Page 1 of 2 1 2 LastLast
Results 1 to 15 of 19
  1. #1
    Join Date
    Aug 2005
    Posts
    17

    function for file.exist

    Ok, basically I have AMS doing
    Code:
    if File.DoesExist(CDrive.."blah") then
    	File.Run(CDrive.."blah", "/S", "", SW_MINIMIZE, true);
    end
    if File.DoesExist(sDrive.."blah") then
    	File.Run(sDrive.."blah", "/S", "", SW_MINIMIZE, true);
    end
    CDrive is cdrom and sDrive is systemdrive. I do this file.exist for around 50 files. I was hoping maybe setting up a function to do file.exist and switch between cdrive and sdrive and then set it to a variable so I could reduce how much is written, but Im stumped on how to set this up...basically I want a set variable to be the output. It need to search a set place on CDrive and sDrive and then output to the variable the exact location...so for instance, lets say I was doing this with 7zip.exe

    Code:
    function Blah (filename.exe)
         if File.DoesExist(CDrive.."\\7zip.exe") then
              variable = CDrive.."\\7zip.exe"
         if File.DoesExist(sDrive.."\\7zip.exe") then
              variable = sDrive.."\\7zip.exe"
    and on page on show it would do somethig like this
    Code:
    Blah(7zip.exe)
    File.Run(variable, "/S", "", SW_MINIMIZE, true)
    any help is greatly appreciated.

  2. #2
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    You could try this

    Code:
    function Blah (filename.exe)
         local variable = nil;
         if File.DoesExist(CDrive.."\\7zip.exe") then
              variable = CDrive.."\\7zip.exe";
         elseif File.DoesExist(sDrive.."\\7zip.exe") then
              variable = sDrive.."\\7zip.exe";
         else
              variable = nil;
         end
         return variable; --returns the variable 
    end
    
    variable = Blah(7zip.exe)
    File.Run(variable, "/S", "", SW_MINIMIZE, true)
    TJ-Tigger
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

  3. #3
    Join Date
    Aug 2005
    Posts
    17
    What about this?

    Code:
    function Blah (filename.exe)
         local variable = nil;
         if File.DoesExist(CDrive.."\\" .. filename.exe) then
              variable = CDrive.."\\" .. filename.exe;
         else
              if File.DoesExist(sDrive.."\\" .. filename.exe) then
                   variable = sDrive.."\\" .. filename.exe";
              else
                   variable = nil;
              end
              return variable; --returns the variable 
         end
    then when I want to call the function for each executable, I would do this

    Code:
    Blah(7zip.exe)
    File.Run(variable, "/S", "", SW_MINIMIZE, true)
    right?

  4. #4
    Join Date
    Jul 2002
    Location
    USA
    Posts
    3,959
    Code:
    variable = Blah("7zip.exe")
    File.Run(variable, "/S", "", SW_MINIMIZE, true)

  5. #5
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    Since the function you created returns the variable you want to make sure and assign a variable name for your function

    Code:
    variable = Blah("7zip.exe")
    File.Run(variable, "/S", "", SW_MINIMIZE, true)
    
    --or
    
    File.Run(Blah("7zip.exe"), "/S", "", SW_MINIMIZE, true);
    If the files are all listed in a table you could traverse the table using a for loop that would run that command for each file in the table

    Code:
    tFiles = File.Find("AutoPlay\\Docs", "*.exe", false, false, nil, nil);
    if tFiles then
        for index, strFilename in tFiles do
            File.Run(Blah(strFilename), "/S", "", SW_MINIMIZE, true);
        end
    end
    Tigg
    TJ-Tigger
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

  6. #6
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    No surprise there. Worm beat me to the punch.
    TJ-Tigger
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

  7. #7
    Join Date
    Aug 2005
    Posts
    17
    I would love to create a table, but the switches change from program to program.

    And I was using KillProcess and CopyFolder functions as a basis...and I notice in those they dont use the variable = KillProcess(sProcess), so i didnt think id need it, I guess I should have explained what I wrote a little more...for my purpose, Blah is KillProcess (its blah right now cuz I havent decided on a name) and filename.exe is sProcess (again, havent decided on the name for it yet...might just be sFilename)

    PS ya know what, skip that paragraph...TJ_Tigger thank you very much, after reading the entire post, I notice its possible to write it in File.Run and save lines...so that what ill do...I appreciate everyones help in this as I am trying to cut down on how many lines this project consists of...right now (without this function), Im at around 675 lines of code (this is using wordpad to count the lines with no wordwrap)...so as you can see, its a pretty large project. This will save me 343 lines. so thank you TJ_Tigger and Worm

  8. #8
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    NP, hope it helps

    If the processes are always the same you could build the table in your code, or in a file for that matter and have both the filename and switches for each program.

    i.e.
    tblPrograms = {}
    tblPrograms.1 = {filename = "c:\\path\\to\\file\\filename.exe", switch = "/S"}
    tblPrograms.2 = {filename = "c:\\path\\to\\file\\filename2.exe", switch = "/S"}
    tblPrograms.3 = {filename = "c:\\path\\to\\file\\filename3.exe", switch = "/S"}
    tblPrograms.4 = {filename = "c:\\path\\to\\file\\filename4.exe", switch = "/S"}
    tblPrograms.5 = {filename = "c:\\path\\to\\file\\filename5.exe", switch = "/S"}

    Then when you run that file you would do this.
    Code:
        for index, value in tblPrograms do
            if Blah(tblPrograms[i]["filename"]) then
                File.Run(tblPrograms[i]["filename"], tblPrograms[i]["switch'], "", SW_MINIMIZE, true);
            else
                Dialog.Message("Error", "File did not exist");
            end
        end
    Tigg

    for index, strFilename in tFiles do
    File.Run(Blah(strFilename), "/S", "", SW_MINIMIZE, true);
    end
    Last edited by TJ_Tigger; 08-18-2005 at 01:49 PM.
    TJ-Tigger
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

  9. #9
    Join Date
    Aug 2005
    Posts
    17
    I have actually thought about the table...so my question is this, if I write all the apps to a textfile with switches, how do I get it to read the 1st portion to a table and then the second to another table so that it can use table1 for file and table2 for switches...the text file would look something like this

    Code:
    7zip.exe               /S
    bittornado.exe       /S
    tgf.exe                 /VERYSILENT /SP- /NORESTART
    something like that is what i was thinking about, but I have no idea how to get it to use the textfile...I know there is TextFile.ReadToTable and that kin of thing, but it doesnt really explain about setting tabs in the textfile and if the first part can be put to one table and then a tab would signfiy parsing it to the 2nd table.

    the reason for the textfile is that it would be changeable...some things woul get run, while others do not...I would have a full list backup, but the textfile it reads from could contain all or one, so I really wouldnt want the programs "coded" into the app.

    Again, I cant tell you how much I appreciate the help. This is the first thing Ive done in AMS and I really dont know all that much about the program.

  10. #10
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    There are lots of ways you could do it. If you do use a text file I would suggest putting some unique delimiter between the filename and the executable, then you could us the DelimitedStringToTable function that is included with AMS.

    You could then read the file to a table using the above specified action then break out the string into its different parts and check for the file then run if necessary.

    If you don't want to use delimiters, you could search for a "/" for the start of the switches or the "exe" as the end of the file and grab (String.Right and String.Left) the rest from there.

    HTH
    Tigg
    TJ-Tigger
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

  11. #11
    Join Date
    Aug 2005
    Posts
    17
    I hate to do this, so im sorry, but I dont see anywhere on how to use delimitedstrings in the help file...I found that it seems to be a lua script, but i dont know how to enable the script or if it is always enabled and then i dont know exactly how to work through it. Is there any way you can give me some info on it, or help me on how to use it? I appreciate your help.

  12. #12
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    It is in the Gallery pane. Look for the scriplets section in the Gallery and you should find the Delimited string lua file. Just copy that code into your global functions and you then have use of the function in your project.

    Tigg
    TJ-Tigger
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

  13. #13
    Join Date
    Aug 2005
    Posts
    17
    Ok, well i found it, but im not sure how to go about using it for this method...if i understand correctly, i first have to TextFile.ReadToTable, where the textfile has the name of the program, a delimiter, and the silent switches. Then I use DelimitedTableToString...this is where I seem to have problems...i just dont see where I get the variables from...I would need the program to be one variable and the switch to be a second variable...also, String.Right and String.Left require me to use a certain number of characters to read from, but with this type of situtation, the number of characters will always change...Im sorry, I know youre prolly tired of helping me, but maybe if you could give me a example, I could figure out the rest myself.

    My text file so far reads something like this (as an example)
    Code:
    7zip.exe,/S
    Progs.exe,/SP- /VERYSILENT /NORESTART
    Hexeditor.msi,/qb-!
    whatd be really neat is if i could include the directory in there, where the prog exists. like this
    Code:
    7zip\7zip.exe,/S
    Progs\Progs.exe,/SP- /VERYSILENT /NORESTART
    HexEditor\Hexeditor.msi,/qb-!
    Again, Im sorry, and i appreciate your help.

  14. #14
    Join Date
    Sep 2002
    Location
    Sol 3
    Posts
    3,160
    Not a problem on the help. If you knew the number of questions that I asked when I first started and continue to ask

    Since you have just two items in the list you can use some simple String functions to extract your data. Here is an example that hopefully will work for you.

    Code:
    --Here is the contents of your text file.  programs.txt
    7zip\7zip.exe,/S
    Progs\Progs.exe,/SP- /VERYSILENT /NORESTART
    HexEditor\Hexeditor.msi,/qb-!
    
    --this should extract the information you want from the file
    tblReturn = TextFile.ReadToTable("AutoPlay\\Docs\\programs.txt");
    if tblReturn then  --if the table is valid then proceed
    	tblProgs = {}; --build a place to store the contents of the text file.
    	for i,v in tblReturn do --traverse each item in the table
    		--search for the position of the delimeter in the string.
    		nPos = String.Find(v, ",", 1, false);
    		if nPos ~= -1 then --the delimeter was found
    			tblProgs[i] = {};
    			tblProgs[i].Program = String.Left(v, nPos -1);--Get the program information
    			tblProgs[i].Switches = String.Mid(v, nPos +1, -1);--Get the switches
    		end
    	end
    end
    
    --Then if you wanted to run it
    if tblProgs then
    	for i,v in tblProgs do
    		File.Run(tblProgs[i].Program, tblProgs[i].Switches, "", SW_MINIMIZE, true);
    		--You can use the following line if you need the switches to be in quotes
    		--File.Run(tblProgs[i].Program, string.format("%q", tblProgs[i].Switches), "", SW_MINIMIZE, true);
    	end
    end

    Hope that helps get you started.
    Tigg
    TJ-Tigger
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

  15. #15
    Join Date
    Aug 2005
    Posts
    17
    thank you soo much...ok a couple of questions
    I included a msi file in there just to see what your response on that was...but its ok, ill ask about it now and in accordance with this new script.
    First things first...I would like to combing this with the FindDrive script, so Im assuming something like this would be correct..

    Code:
    File.Run(FindDrive(tblProgs[i].Program), tblProgs[i].Switches, "", SW_MINIMIZE, true);
    also, what is the deal with the switches in quotes? do i need them to be in quotes? Im not sure...or if they arent does that mean they should be in quotes in the textfile?

    Now for the msi portion (I may break the programs up and have one for executables and one for msi files)
    Code:
    Shell.Execute(FindDrive(tblProgs[i].Program), "open", tblProgs[i].Switches, "", SW_MINIMIZE);
    or maybe there is a way to seperate the msi and exe in the textfile without me having to use 2 txt files? Looks like it is almost finished...WHEW! LOL. Thank you TJ_Tigger.

    PS. Also, do I just run it once, or do I need to run it each time for each program...Im pretty sure its just once since it uses the for command. just checking
    Last edited by threaded; 08-27-2005 at 02:43 PM.

Page 1 of 2 1 2 LastLast

Similar Threads

  1. Function: String.RandomFromPattern
    By Brett in forum Setup Factory 8.0 Examples
    Replies: 0
    Last Post: 10-28-2004, 08:09 AM
  2. Bizarre Callback Function Behaviour - Can anyone help?
    By SRJ in forum AutoPlay Media Studio 5.0
    Replies: 3
    Last Post: 06-30-2004, 09:16 PM
  3. Function: Validate the Contents of an Input Object
    By Lorne in forum AutoPlay Media Studio 5.0 Examples
    Replies: 2
    Last Post: 06-17-2004, 08:47 AM
  4. Function: Increase/Decrease Audio Playback Volume
    By Adam in forum AutoPlay Media Studio 5.0 Examples
    Replies: 0
    Last Post: 05-31-2004, 02:28 PM
  5. Function: Resize & Center an Image
    By kpsmith in forum AutoPlay Media Studio 5.0 Examples
    Replies: 0
    Last Post: 05-17-2004, 01:36 PM

Posting Permissions

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