Neophyte User: Get list of files in a folder to iterate

Hi All:

I am trying to do something I feel should be, and probably is, easy. My goal is the following:

Put list of files, in this case image names, into a variable
Open each file in the list - one at a time (I need the name of each file for our app)
Continue the script after stepping through the files

Aside from catching this fish for me I have a couple other questions that could help me down the road (besides reading the manual).
* I'm a windows guy. How does Eggplant reference folders on a Mac (i.e., folder on the desktop of the SUT)?
* How can I echo the value of the current element in my list?

Thank you,

~ Doug

Comments

  • Hi Doug,

    EggPlant doesn't have any intrinsic knowledge of the SUT's file system. To open files on the SUT, you have to script the actions you would perform if you were sitting in front of the SUT yourself. So if you wanted to open files on the SUT desktop, the script might look something like this:
    put ("File1", "File2", "File3") into fileList // Each item is an image of a file icon on the SUT desktop
    
    repeat with each item myFile in fileList
    	DoubleClick myFile // Doubleclick the current file icon to open the file
    	Put myFile // Tells you the current element in script output
    end repeat
    

    After that, the script would just continue on to the next line.

    I hope this answers your questions!

    Happy Testing,
    Pamela


    :):):) [/code]
  • Hi Pamela,

    Thank you for your quick post.

    I may not have articulated my question very well. The files in the folder are very likely to change. I actually need to get a list of the file names in the folder. I'm using EggPlant to test multiple browsers on both Macintosh and Windows. Our application is unable to work using a double-click to open files.

    My goal is to do something like a DOS Dir command (file names only) and put the list into a variable. Once the names are in the variable I'd like to iterate through them.

    Will your code snippet work for this scenario as well?

    Thank you,

    ~ Doug
  • Let's see if this one does the trick… This script opens a terminal on your Mac SUT and uses the unix ls command to get a list of the files in your folder. (Script assumes that your Finder is using column view.)
    // Open Terminal
    Click "Finder_Dock_icon"
    TypeText CommandKey, Shiftkey, "a" // Go to Applications folder
    Click "Utilities_folder"
    DoubleClick "Terminal_app"
    
    // Get your list
    TypeText "cd Desktop/DougsTestFiles" // changes directory to your folder
    TypeText "ls | pbcopy" // ls is a list command, and pbcopy puts the output  of it on your pasteboard
    Set fileList to remoteClipboard (5) split by return // Allows up to 5 seconds for new pasteboard contents, then sets fileList to the pasteboard contents separated by returns
    
    // Iterate over your list
    Repeat with each item testFile of fileList
    	Put "Now testing " &  testFile // Tells you in output which file you're on
    	// and then do whatever you intend to do with the file…
    end repeat
    
    Happy Testing,
    Pamela :)
  • klausmoranklausmoran Member
    edited January 2012
    Thank you Pamela!
  • Thank you. That worked perfectly
Sign In or Register to comment.