![]() ![]() If you give a program a "relative path", it will figure out the full name by itself, using the location of the script as a reference point (your "working directory"). You can tell that it's a relative path because it doesn't start with a slash or C: (C:, D:, etc. ![]() One very good and very simple solution to this is to use "relative paths". ![]() If I wrote the script on a Mac, and give it to a Windows user, the problem is even worse: they would have to change the beginning to "C:" and reverse all of the slashes. If I'm ever planning on sharing my script, I have just guaranteed an error: If I try to open or write any files it won't work because they wouldn't exist. This has a big downside, though: My computer username is not the same as yours, and if I own two computers, the username might not be the same on both machines. Up until now, we've been talking about "absolute paths". Make your paths more "future-proof": Relative paths There should be a field showing you the path of the item. In Windows, you can right click it, and select "Properties". In Mac's finder, select the item, and from one of the dropdown menu above select "Get info", or hit ⌘ + i. You can pretty easily get the path of a folder or file by looking at its Info/Properties. Note that files that are above this folder (like those is C:\ or / ("root")) typically belong to the system, and you are not supposed to mess with those files unless you know what you're doing. This is where all files that belong to you (your computer user) live. The house icon on your point and click file browser represents your "home directory", and is a graphic representation of something like /Users/, or C:\Users\. "Directory" is the older name for "folder" that is commonly used by programmers. Each slash (forward slash in Mac and Linux, backslash in Windows) represents a "directory". In Praat scripts, when you are going to read (open) or write (save) a file, you use paths and write them in the format above, you are not going to emulate point and click behavior. VidFile$ = "C:\Users\daniel\Desktop\myVideos\Graduation.mp4" VidFile$ = "/Users/daniel/Desktop/myVideos/Graduation.mp4" VidFile$ = "/home/daniel/Desktop/myVideos/Graduation.mp4" These nice user interfaces somewhat obscure the fact that this file's full name (full path) is something like this (I'm saving the path name to a string variable, vidFile$): This is definitely a user-friendly way of doing things in a point and click environment. We're used to interacting with that file through something like Mac's Finder or Windows' File Explorer, where we click our way to the file, navigating through folders as if they were "places". Let's pretend we have a folder on our Desktop called "myVideos", that contains a movie file called "Graduation.mp4". ![]() So, what is a path? A path is essentially a location on your file system, aka the name of a file or folder. This chapter's goal is bring you up to speed on how files are named programmatically, allowing you easily open and save files from your scripts, and understand any errors when you've made a mistake. I'm under the impression that with more recent upgrades of Praat some of this has been made easier. Maybe you've had the experience of trying to get a script to open or write a file, and been driven mad with a "File not found" error. I personally found paths to be a big pain in the kiester when I first started programming and programming for Praat. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |