Announcement

Collapse
No announcement yet.

How to append folder name to files

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to append folder name to files

    I'v been looking for a solution to this problem from very long. I try to search through stackoverflow, and other resources but don't understand the solutions given (which are mostly shell scripts) and after searching for some time I decide to check it later, and it's been pending form so long. But today I thought to post this thread.

    Okay so, I have a folder structure given below.

    Click image for larger version

Name:	Screenshot_20190817_194428.png
Views:	1
Size:	13.1 KB
ID:	649507

    What I want to do is append "2008-dec" to "MCS-021.pdf" so it should become "2008-dec_MCS-021.pdf" and so on for the rest of the file. Then this should repeat for the next folder "2008-jun"

    I have these files in all the folders the name is same only the folder name is different.

    Thanks..:-)

    #2
    There is no easy solution, even if you do shell scripting or programming at a high level. There is a large risk for error with so many of the same file names.

    Of course the directory is part of each file's metadata - the path is always available when viewing or updating. If you frequently enter into these files, you could rename them as you go into each. Other than that, I would just be repeating what you have already found. Sorry!
    The next brick house on the left
    Intel i7 11th Gen | 16GB | 1TB | KDE Plasma 5.27.11​| Kubuntu 24.04 | 6.8.0-31-generic



    Comment


      #3
      Well, you won't be able to to that without using scripts, will you :·)
      Now, something like
      Code:
      DIRS=`ls -l $MYDIR | egrep '^d' | awk '{print $9}'`
      for DIR in $DIRS
      do
      echo  ${DIR}
      done
      should list all the directories in your current one.
      So you could pass them to the script as variables and append them (or prepend them, as your case seems to be) to the filenames.

      Then recursively
      cd $DIR , append or prepend $DIR to all files, and cd ..

      Alternatively,
      Code:
      for file in MCS*
      do
      stat -c %y "$file"
      done
      will extract the date from the files, you could choose the part of the string to use and prepend that.

      Obviously, the likelihood of errors while testing this kind of thing is high, so you should copy the stuff to a "test" area and experiment there.
      For example, '{print $9}' returns the directory name on my system, it may return something else on yours.

      If you'd like to go for it, I can maybe cook up a script to try, or you can ask in stackexchange-like places... which is probably best :·)

      Comment


        #4
        We forget the powerful and cool GUI tool with the old KDE 3 era let's-tack-a-K-on-every-app name: Krename

        it will do exactly this

        Click image for larger version

Name:	Screenshot_20190817_115518.jpg
Views:	1
Size:	79.4 KB
ID:	644285

        Click image for larger version

Name:	Screenshot_20190817_115643.jpg
Views:	1
Size:	64.7 KB
ID:	644286


        You do need to do some tweaking to make it fit your needs.
        The '$' represents the original file name, so you can move that to the end of you like, and insert a dash as I have, or spaces, underscores, whatever you like.

        Comment


          #5
          Originally posted by Don B. Cilly View Post
          Well, you won't be able to to that without using scripts, will you :·)
          Well, there you go, it looks like you will
          Very nice utility that.

          Still,
          Obviously, the likelihood of errors while testing this kind of thing is high, so you should copy the stuff to a "test" area and experiment there.
          is probably still valid.
          Or the results may be in the neighbourhood of
          Click image for larger version

Name:	b2.png
Views:	1
Size:	49.7 KB
ID:	644287

          Comment


            #6
            Krename ,,,,yes I remember that now .

            it seams that once installed (sudo apt install krename) it is integrated into both Dolphin and Krusader (if you happen to have that) in Dolphin it will be found in rite click>actions .

            if one say "ctrl+a" a bunch of files then "right click>actions>rename with krename" the hole set will be loaded in the Krename window that will open.

            VINNY
            i7 4core HT 8MB L3 2.9GHz
            16GB RAM
            Nvidia GTX 860M 4GB RAM 1152 cuda cores

            Comment


              #7
              Originally posted by Don B. Cilly View Post
              Well, there you go, it looks like you will
              Very nice utility that.

              Still,

              is probably still valid.
              Or the results may be in the neighbourhood of
              [ATTACH=CONFIG]8246[/ATTACH]



              I found "krename" interesting. Let me try it out for a couple of days if I face any problem I may reply again. Like always I got the solution to a problem which is difficult to tackle in other commercial OS. Thanks everyone.

              Comment

              Working...
              X