Results 1 to 2 of 2

Thread: naming files same as folder name

  1. #1
    Join Date
    Jul 2014
    Beans
    2

    naming files same as folder name

    Hi,
    I have an ftp folder and people uploading directories included files. I want to write a script that names files same as folder name
    example;

    folder name is : 800_D1_TOC
    file name : 800-d1-tocaree.xcf

    I want to change file to 800_D1_TOC with a script

    is there any way to do this.

    but there are a lot of folders and su folders I want to change names of files with specified folders like

    if script see a folder named 800_D1_TOC script will rename the file with the same name of folder

    the folders names like;
    800_D1_TOC
    800_D1_ATA
    800_D1_MTN
    1800_D2_TOC
    1800_D1_ATA
    1800_D1_MTN

  2. #2
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: naming files same as folder name

    800_D1_TOC/800-d1-tocaree.xcf is supposed to become 800_D1_TOC/800_D1_TOC?

    assuming there is only 1 item in a relevant dir

    Code:
    dirs=( 800_D1_TOC
             800_D1_ATA
             800_D1_MTN
             1800_D2_TOC
             1800_D1_ATA
             1800_D1_MTN )
    
    for d in "${dirs[@]}"
    do
       echo mv "$d"/* "$d/$d"
    done
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •