setMediaPath and getMediaPath
Quick tutorial on using the mediaPath.
JES provides a setMediaPath() function that you always use in the command area.
If in the command area, you type
>>> setMediaPath()
This brings up a dialog similar to that for pickAFile(). Instead of picking a file, choose a folder. This folder is now your mediaPath. You get a message in the command area confirming this.
Now you can refer to any file in that folder – either in the command area or in a function – by using the getMediaPath() function.
Say that folder contains a file called "picture.jpg", you can show that picture file in your code now by saying
show(makePicture(getMediaPath("picture.jpg"))
Why use get/setMediaPath?
If picture.jpg is in a folder called "/Users/potts/Documents/ed/1315/2008-Spring/Pictures/" I could setMediaPath to this folder and then do
show(makePicture(getMediaPath("picture.jpg"))
as above. Or, I could simply type
show(makePicture("/Users/potts/Documents/ed/1315/2008-Spring/Pictures/picture.jpg"))
What is the advantage of using getMediaPath? Why not just put the full path name in the call to makePicture?
- It saves you having to put the full path in your code. If a file ever moves location, your code will still work provided you change the mediaPath to refer to its new folder before running that function.
- It aids portability. If you and a TA both have a file called "picture.jpg" (it doesn't even have to be the same picture), any code that refers to getMediaPath("picture.jpg")) will work on both computers. If, however, you included the full path to the file on your hard disk, that would NOT work on your TA's computer, because he or she has a different folder structure.

Links to this Page