Problems moving and renaming pictures with this code, what wrong?

Discussion in 'Ruby' started by Fily Salas, Mar 23, 2011.

  1. Fily Salas

    Fily Salas Guest

    Hi,

    I have been reading the book called =E2=80=9CLearning to Program=E2=80=9D=
    and I have to
    say it, for beginners this is a great book, anyways, while practicing
    the exercises found in the book I came across this code that for some
    reason it doesn=E2=80=99t work.

    I have some .jpg pictures located in a folder called =E2=80=9Ctemp-photos=
    =E2=80=9D in my
    desktop and I want to rename them and then move them to a folder which
    is also located in my desktop but in a folder called =E2=80=9Cmy-photos=E2=
    =80=9D and I=E2=80=99m
    trying the code below but when I run it, it just doesn=E2=80=99t do anyth=
    ing, no
    errors but the pictures don=E2=80=99t get moved or renamed.

    Any idea what am I doing wrong? I don=E2=80=99t actually need this progr=
    am but
    since I=E2=80=99m practicing I want to understand what=E2=80=99s going on=
     
    Fily Salas, Mar 23, 2011
    #1
    1. Advertisements

  2. I have some .jpg pictures located in a folder called =93temp-photos=94 in=
    my
    Since temp-photos is a directory, should not the glob pattern be:

    pic_names =3D Dir['/Users/userName/Desktop/temp-photos/*.{JPG,jpg}']

    --=20
    Anurag Priyam
    http://about.me/yeban/
     
    Anurag Priyam, Mar 23, 2011
    #2
    1. Advertisements

  3. Fily Salas

    Fily Salas Guest

    I know, shame on me I should know that :(

    Thanks a lot for your help!
     
    Fily Salas, Mar 23, 2011
    #3
  4. Fily Salas wrote in post #988915:
    You can do this in one step.
    You can instead do:

    pic_names.each_with_index do |name, pic_number|
    [...]
    end

    (but pic_number would start at 0.)
    You can also do:

    new_name = "%s%0d2.jpg" % [batch_name, pic_number+1]

    (I added 1 to pic_number because now it starts at zero.)
     
    Albert Schlef, Mar 25, 2011
    #4
  5. Fily Salas

    Fily Salas Guest

    Thank you for the simplified version.
     
    Fily Salas, Mar 25, 2011
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.