Note that there are some explanatory texts on larger screens.

plurals
  1. POMoving image to another folder
    primarykey
    data
    text
    <p>currently reading Learn To Program. Im at page 91-92 where you create a program that moves images from your USB drive to desired location and changing the name of each image. But i get the follwing error when runing the program. Using Ubuntu as you can tell, but get <strong>"Invalid cross-device link"</strong>. Any ideas of how to solve this?</p> <pre><code>pierre@ubuntu:~/ruby$ ruby move.rb What would you like to call this batch? IMG Downloading 1 files: .move.rb:36:in `rename': Invalid cross-device link - (/media/SanDisk Cruzer Blade/pictures/UMG.jpg, IMG01.jpg) (Errno::EXDEV) from move.rb:36:in `block in &lt;main&gt;' from move.rb:17:in `each' from move.rb:17:in `&lt;main&gt;' </code></pre> <p>This is the code</p> <pre><code># Heres where the pictures are stored Dir.chdir '/home/pierre/Skrivbord' # First we find all of the pictures to be moved pic_names = Dir['/media/SanDisk Cruzer Blade/pictures/**/*.{JPG,jpg}'] puts 'What would you like to call this batch?' batch_name = gets.chomp puts print "Downloading #{pic_names.length} files: " # This will be our counter. We'll start at 1 today, # though normally I like to count from 0. pic_number = 1 pic_names.each do |name| print '.' # This is our "progress bar". new_name = if pic_number &lt; 10 "#{batch_name}0#{pic_number}.jpg" else "#{batch_name}#{pic_number}.jpg" end # This renames the picture, but since "name" has a big long # path on it, and "new_name" doesn't, it also moves the file to the current # working directory, which is now Katy's PictureInbox folder. Since it's a # *move*, this effectively downloads and deletes the originals. And since this # is a memory card, not a hard drive, each of these takes a second or so; hence, # the little dots let her know that my program didn't hose her machine. # (Some marriage advice from your favourite author/programmer: it's all about # the little things.) # Now where were we? Oh, yeah... File.rename name, new_name # Finally, we increment the counter. pic_number = pic_number + 1 end puts # This is so we aren't on progress bar line. puts 'Done, cutie!' </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload