Dump a directory into a container...

Hi All,

I was wondering if there was a way to say something like

put entire contents of "/directoryname" into myBitmaps
repeat with each bitmap of myBitmaps
end repeat

I currently list each bitmap to be dropped into a variable, but I was wondering if I could just drop my bitmaps into the target directory, and have Eggplant simply use what’s there. I know that I could keep a text file and just dump it into the variable each time, but that also requires maintaining a list somewhere else.

I thought about an AppleScript, but my chops aren’t very good.

Or am I just Lazy? :mrgreen:


Sure, Allen, that’s pretty easy to do:

put "path/to/directory/" into myDirectory
repeat with each item of files(myDirectory)
    put myDirectory & it into myBitmap
    put the size of file myBitmap
    // do whatever other file manipulations you want to do
end repeat

Notice that you need to prepend the path when referring to the files returned by the files() function; this function returns just a list of filename strings that are not tied to the actual file objects in the filesystem. This issue can be simplified a little bit by setting the current working directory to be the directory that holds your bitmaps:

set the directory to "path/to/directory/"
repeat with each item of files()
	put the size of file it
end repeat

Now all of the references to files are assumed to be to files in the specified directory, so you don’t need to include it explicitly.
Hope this helps.

Thanks Matt.

For some reason it’s not working. Here’s what I’ve got at the top of the script:

set currOS to "XP"
put currOS&"/MenuItems/FileMenu/Items" into itemsDir
put currOS&"/Menuitems/FileMenu/Verify" into verifyDir
ask files(itemsDir)--check to see what is in the directory

Unfortunately, the last statement returns 0 as the value, saying the folder is empty, when there are a couple of dozen files in the directory. I tried setting the working directory as you suggested as well, but

 set the directory to "path/to/files"
ask directory

still evaluates as the default directory for Eggplant.

What am I missing?



My guess is that in your example “XP” is a subdirectory of the images directory of your current suite. When you specify a directory, you have to either provide the full path starting at the root directory of the file system, or a relative path starting from the current working directory. If the current working directory is ~/Documents/, and your suite is in that directory, then you could specify the relative path as

set currOS to "MySuite.suite/Images/XP"

or you could specify the full path as

set currOS to "/Users/Allen/Documents/MySuite.suite/Images/XP"

There are some tricks you can use to get some of the path information without having to know it or to type it. One I like to use to get the full path to the Images directory (or a subdirectory) requires that you already know the name of an image in that directory:

set itemsDir to the directory of file(imageInfo("XP/someImage").imageName)

Similarly, if you want to get the full path to the Images directory of the suite that contains the current script, you can do this:

put my directory into scriptDir
delete the last word delimited by "/" of scriptDir
put scriptDir & "/Images/XP" into currOS 

The fact that you can refer to image names in commands and functions using a path relative to the Images directory is a special case – the Eggplant commands and functions use an internally specified search path that includes the Image directories in open suites and helper suites. Eggplant just “knows” that images have to be in Image directories or their subdirectories. But the SenseTalk file system commands and functions work outside of that restriction, so you need to specify paths to things in the same way that you have to when you do file system operations in a terminal window.

I hope this explanation has done more to clarify than to confuse. Let me know if you have any other questions.

  • Matt