In this video, we go over functions provided by ruby for performing filesystem operation in directories. You'll find a lot of places where filesystem navigation is required such for finding required YAML files or libraries and I intend to make you guys experts in directory navigation using this lesson!! :)
Let's keep the momentum going to becoming ruby experts in a single day!
** QUIZ FOR THIS SESSION ** - https://goo.gl/forms/3eoi9VPVCwW5YaUz2
The functions we cover include
Base functions
pwd/getwd - Gets current working directory. Starts on the directory where script is executed and changes when pwd or chdir is executed
home - Home directory of current user
Creation
mkdir - make a directory
delete/rmdir - deletes a directory
exist? - check if directory exists
empty? - check if directory is empty
Navigation
chdir - changes directory
entries - list all children (including standard directory links "." and ".."
children - list only children (excludes "." and "..")
glob - search utility
================Glob Flags ==========================
*
Matches any file. Can be restricted by other values in the glob. Equivalent to / .* /x in regexp.
*
Matches all files
c*
Matches all files beginning with c
*c
Matches all files ending with c
c
Match all files that have c in them (including at the beginning or end).
Note, this will not match Unix-like hidden files (dotfiles). In order to include those in the match results, you must use the File::FNM_DOTMATCH flag or something like "{*,.*}".
**
Matches directories recursively.
?
Matches any one character. Equivalent to /.{1}/ in regexp.
[set]
Matches any one character in set. Behaves exactly like character sets in Regexp, including set negation ([^a-z]).
{p,q}
Matches either literal p or literal q. Equivalent to pattern alternation in regexp.
\
Escapes the next metacharacter.
=====================================================
Low Level Child Navigation
open/new - open a directory and give reference pointer to first child
read - read child and seek to next postiion
seek - seek to a particular child (starts from 0)
tell/pos - tells current position of pointer
rewind - resets pointer to 0
close - closes directory resource
to_path - full path of operator used to initialize this
Comment below for any questions you want answered.
If you found this video useful, like and subscribe.
If you want to make my day, please follow me on social media
Twitter : / progbypractise
Facebook : / programming-by-practising-1713777571991152 Website : http://programmingbypractising.wordpr...