Copying Files
Let’s put the File class to some practical use by writing a simple file backup program. When you run copy_files.rb, you will be asked to choose a directory to copy from (the source directory) and another directory to copy to (the target directory). Assuming both directories exist, the program will then copy all the files from the source directory to the target directory. If the target directory does not exist, it will ask you whether you would like to create it, in which case you should enter Y to accept. I’ve supplied a source directory for you; just enter the name srcdir when prompted. When asked for a target directory, enter targetdir in order to create a subdirectory of that name beneath the current directory.
The program initializes ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access