#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    12
    Rep Power
    0

    Have Problems adding an extension to files in a directory


    I'm Trying add an .edi extenion to the file that originally looks like this: i.gtp.030206065504
    I would like it to look like this: i.gtp.030206065504.edi


    When using this code Im getting the error: Cannot rename *gtp.* to *gtp.*edi:

    This is my code:


    OLDSUFFIX=
    NEWSUFFIX=edi
    for FILES in *gtp.*"$OLDSUFFIX"
    do
    NEWNAME=`echo "$FILES" | sed -e "s/${OLDSUFFIX}\$/$NEWSUFFIX/"`
    mv "$FILES" "$NEWNAME"
    done

    Any Suggestions would be appreciated!!!!
  2. #2
  3. No Profile Picture
    aka Stef
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    18
    Rep Power
    0
    Hi,

    if you just have to add the ".edi" extension to all the files, you could do just this:

    for $files in *.gtp.*
    do
    mv $files $files.edi
    done

    OR

    for $files in *.gtp.*
    do
    NEWSUFFIX=".edi"
    mv $files $files$NEWSUFFIX
    done


    Hope this helps,
    Stef.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    191
    for ($i in *); do mv "$i" `basename "$i"`.edi; done

    is my "standard rename function"

IMN logo majestic logo threadwatch logo seochat tools logo