# Write a script that searches for all image files starting with 'Screen Shot' and ending with .png.
# Have the script move all such files into a new directory in your Documents directory
# Assign the new destination folder a standardized name that includes an ISO 8601 date/time stamp.
# Have the script zip/compress the screen shot image folder.
path = 'folder/to/zip' # Replace this with your folder path
zipped = 'whatever.zip' # Replace this with your zip name
zip_succeeded = system("zip -r #{zipped} #{path}") # true if succeeded
Me: What's the practice for determining how precise you need to be when specifying a directory variable in a script for moving items?
-
Where to run the script from
-
What privileges does the script need (sudo?)
-
I think of it that there are 3 kinds of paths (I'm only talking strings right now)
relative path
(for example, 'assets/some-file.txt'). Relative to where script was ran fromabsolute path
(for example, /etc/foo/bar.txt). Starts with a /, explains exactly where file isscript-relative path
(for example, "#{File.dirname(FILE)}/foo/bar.txt"). This will look for a file RELATIVE TO wherever some-script.rb lives- Script-relative paths always look like:
"#{File.dirname(__FILE__)}/#{relative_path}"
where relative_path is the path relative to the script you are running
-
So it depends what you are acccessing.
relative paths
- for user filesabsolute paths
- for system and global files (logs and stuff)script-relative paths
- for files that you provide along with your script (default config files, template files, etc. Best to treat script-relative files as read-only)Relative
andabsolute
are important to understand.Script-relative
is more like a technicalityRelative
- no slash at beginning.Absolute
- slash at beginning Every language has their own way of specifying script-relative paths (relative and absolute are given)
-
__FILE__
is the path to the currently running script.File.dirname(path)
takes a file path and strips off the filename at the end.File.dirname(__FILE__)
therefore gives you a path to the directory that the currently running script lives in.
(Roger in this case is my professional mentor who's working with me on my learning j o u r n e y )