Copy and rename files to a sequential numbering with subdirectories Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election Results Why I closed the “Why is Kali so hard” questionBulk rename files with numberingTrouble with mv and adding the daterename files with rename commandHow to mass rename files with ill-formed numbering?Recursive copy files with renameRename certain files with part of parent directory nameRename files to change punctuation and numberingDirectory “recursive” last modified dateBatch rename files to a sequential numberingbatch rename files in Ubuntu: sequential numbering, based on order in directory. (Ubuntu 16.04)

How does the secondary effect of the Heat Metal spell interact with a creature resistant/immune to fire damage?

Illegal assignment from sObject to Id

Did Deadpool rescue all of the X-Force?

Why do we need to use the builder design pattern when we can do the same thing with setters?

Take 2! Is this homebrew Lady of Pain warlock patron balanced?

Why weren't discrete x86 CPUs ever used in game hardware?

Why do early math courses focus on the cross sections of a cone and not on other 3D objects?

AppleTVs create a chatty alternate WiFi network

Most bit efficient text communication method?

Selecting user stories during sprint planning

How come Sam didn't become Lord of Horn Hill?

Performance gap between vector<bool> and array

Is there a kind of relay that only consumes power when switching?

Hangman Game with C++

Crossing US/Canada Border for less than 24 hours

When a candle burns, why does the top of wick glow if bottom of flame is hottest?

Is there any word for a place full of confusion?

Has negative voting ever been officially implemented in elections, or seriously proposed, or even studied?

What are the diatonic extended chords of C major?

How often does castling occur in grandmaster games?

ArcGIS Pro Python arcpy.CreatePersonalGDB_management

Why does it sometimes sound good to play a grace note as a lead in to a note in a melody?

Chinese Seal on silk painting - what does it mean?

Trademark violation for app?



Copy and rename files to a sequential numbering with subdirectories



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” questionBulk rename files with numberingTrouble with mv and adding the daterename files with rename commandHow to mass rename files with ill-formed numbering?Recursive copy files with renameRename certain files with part of parent directory nameRename files to change punctuation and numberingDirectory “recursive” last modified dateBatch rename files to a sequential numberingbatch rename files in Ubuntu: sequential numbering, based on order in directory. (Ubuntu 16.04)



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I want to copy files of the given type with inside subdirectories.
I think copy of the zzz.txt file works after copying the files in the abc_folder.
How can i resolve this problem.



AAA
---aaa.txt
---bbb.txt
---zzz.txt
---abc_folder
---aaa.txt
---bbb.txt
---ccc.txt


Wanted output



 AAA
---aaa.txt
---bbb.txt
---zzz.txt
---1.txt
---2.txt
---3.txt
---abc_folder
---aaa.txt
---bbb.txt
---ccc.txt
---1.txt
---2.txt
---3.txt


My code's output



 AAA
---aaa.txt
---bbb.txt
---zzz.txt
---1.txt
---2.txt
---4.txt
---abc_folder
---aaa.txt
---bbb.txt
---ccc.txt
---1.txt
---2.txt
---3.txt


My code



#!/bin/bash

function traverse()
counter=1
for file in "$2"/*
do
if [ ! -d "$file" ]; then
if [[ $file == $3 ]]; then
extension="$file##*."
filename="$file%.*"
cp "$file" "$2/$counter.$extension"
counter=$(($counter + 1))
fi
elif [ $1 == "-R" ] ; then
traverse "$1" "$file" "$3"
fi
done

traverse "$1" "$PWD" "$2"









share|improve this question







New contributor




zblash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


























    0















    I want to copy files of the given type with inside subdirectories.
    I think copy of the zzz.txt file works after copying the files in the abc_folder.
    How can i resolve this problem.



    AAA
    ---aaa.txt
    ---bbb.txt
    ---zzz.txt
    ---abc_folder
    ---aaa.txt
    ---bbb.txt
    ---ccc.txt


    Wanted output



     AAA
    ---aaa.txt
    ---bbb.txt
    ---zzz.txt
    ---1.txt
    ---2.txt
    ---3.txt
    ---abc_folder
    ---aaa.txt
    ---bbb.txt
    ---ccc.txt
    ---1.txt
    ---2.txt
    ---3.txt


    My code's output



     AAA
    ---aaa.txt
    ---bbb.txt
    ---zzz.txt
    ---1.txt
    ---2.txt
    ---4.txt
    ---abc_folder
    ---aaa.txt
    ---bbb.txt
    ---ccc.txt
    ---1.txt
    ---2.txt
    ---3.txt


    My code



    #!/bin/bash

    function traverse()
    counter=1
    for file in "$2"/*
    do
    if [ ! -d "$file" ]; then
    if [[ $file == $3 ]]; then
    extension="$file##*."
    filename="$file%.*"
    cp "$file" "$2/$counter.$extension"
    counter=$(($counter + 1))
    fi
    elif [ $1 == "-R" ] ; then
    traverse "$1" "$file" "$3"
    fi
    done

    traverse "$1" "$PWD" "$2"









    share|improve this question







    New contributor




    zblash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      0












      0








      0








      I want to copy files of the given type with inside subdirectories.
      I think copy of the zzz.txt file works after copying the files in the abc_folder.
      How can i resolve this problem.



      AAA
      ---aaa.txt
      ---bbb.txt
      ---zzz.txt
      ---abc_folder
      ---aaa.txt
      ---bbb.txt
      ---ccc.txt


      Wanted output



       AAA
      ---aaa.txt
      ---bbb.txt
      ---zzz.txt
      ---1.txt
      ---2.txt
      ---3.txt
      ---abc_folder
      ---aaa.txt
      ---bbb.txt
      ---ccc.txt
      ---1.txt
      ---2.txt
      ---3.txt


      My code's output



       AAA
      ---aaa.txt
      ---bbb.txt
      ---zzz.txt
      ---1.txt
      ---2.txt
      ---4.txt
      ---abc_folder
      ---aaa.txt
      ---bbb.txt
      ---ccc.txt
      ---1.txt
      ---2.txt
      ---3.txt


      My code



      #!/bin/bash

      function traverse()
      counter=1
      for file in "$2"/*
      do
      if [ ! -d "$file" ]; then
      if [[ $file == $3 ]]; then
      extension="$file##*."
      filename="$file%.*"
      cp "$file" "$2/$counter.$extension"
      counter=$(($counter + 1))
      fi
      elif [ $1 == "-R" ] ; then
      traverse "$1" "$file" "$3"
      fi
      done

      traverse "$1" "$PWD" "$2"









      share|improve this question







      New contributor




      zblash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      I want to copy files of the given type with inside subdirectories.
      I think copy of the zzz.txt file works after copying the files in the abc_folder.
      How can i resolve this problem.



      AAA
      ---aaa.txt
      ---bbb.txt
      ---zzz.txt
      ---abc_folder
      ---aaa.txt
      ---bbb.txt
      ---ccc.txt


      Wanted output



       AAA
      ---aaa.txt
      ---bbb.txt
      ---zzz.txt
      ---1.txt
      ---2.txt
      ---3.txt
      ---abc_folder
      ---aaa.txt
      ---bbb.txt
      ---ccc.txt
      ---1.txt
      ---2.txt
      ---3.txt


      My code's output



       AAA
      ---aaa.txt
      ---bbb.txt
      ---zzz.txt
      ---1.txt
      ---2.txt
      ---4.txt
      ---abc_folder
      ---aaa.txt
      ---bbb.txt
      ---ccc.txt
      ---1.txt
      ---2.txt
      ---3.txt


      My code



      #!/bin/bash

      function traverse()
      counter=1
      for file in "$2"/*
      do
      if [ ! -d "$file" ]; then
      if [[ $file == $3 ]]; then
      extension="$file##*."
      filename="$file%.*"
      cp "$file" "$2/$counter.$extension"
      counter=$(($counter + 1))
      fi
      elif [ $1 == "-R" ] ; then
      traverse "$1" "$file" "$3"
      fi
      done

      traverse "$1" "$PWD" "$2"






      shell-script rename






      share|improve this question







      New contributor




      zblash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      zblash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      zblash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Apr 14 at 16:34









      zblashzblash

      11




      11




      New contributor




      zblash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      zblash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      zblash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          1 Answer
          1






          active

          oldest

          votes


















          0














          With zsh:



          #! /bin/zsh -
          autoload zmv
          incr='++count[$1]'
          typeset -A count
          zmv -n '(**/)(*)(.txt)' '$1$((incr))$3'


          (remove -n when happy)



          The idea being to use an associative arrays whose key is the directory for counting.



          We need the intermediary incr variable or otherwise it wouldn't work for directory names containing ].






          share|improve this answer























          • I want to use just pure bash

            – zblash
            Apr 14 at 17:20











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          zblash is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f512437%2fcopy-and-rename-files-to-a-sequential-numbering-with-subdirectories%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          With zsh:



          #! /bin/zsh -
          autoload zmv
          incr='++count[$1]'
          typeset -A count
          zmv -n '(**/)(*)(.txt)' '$1$((incr))$3'


          (remove -n when happy)



          The idea being to use an associative arrays whose key is the directory for counting.



          We need the intermediary incr variable or otherwise it wouldn't work for directory names containing ].






          share|improve this answer























          • I want to use just pure bash

            – zblash
            Apr 14 at 17:20















          0














          With zsh:



          #! /bin/zsh -
          autoload zmv
          incr='++count[$1]'
          typeset -A count
          zmv -n '(**/)(*)(.txt)' '$1$((incr))$3'


          (remove -n when happy)



          The idea being to use an associative arrays whose key is the directory for counting.



          We need the intermediary incr variable or otherwise it wouldn't work for directory names containing ].






          share|improve this answer























          • I want to use just pure bash

            – zblash
            Apr 14 at 17:20













          0












          0








          0







          With zsh:



          #! /bin/zsh -
          autoload zmv
          incr='++count[$1]'
          typeset -A count
          zmv -n '(**/)(*)(.txt)' '$1$((incr))$3'


          (remove -n when happy)



          The idea being to use an associative arrays whose key is the directory for counting.



          We need the intermediary incr variable or otherwise it wouldn't work for directory names containing ].






          share|improve this answer













          With zsh:



          #! /bin/zsh -
          autoload zmv
          incr='++count[$1]'
          typeset -A count
          zmv -n '(**/)(*)(.txt)' '$1$((incr))$3'


          (remove -n when happy)



          The idea being to use an associative arrays whose key is the directory for counting.



          We need the intermediary incr variable or otherwise it wouldn't work for directory names containing ].







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Apr 14 at 16:53









          Stéphane ChazelasStéphane Chazelas

          315k57597955




          315k57597955












          • I want to use just pure bash

            – zblash
            Apr 14 at 17:20

















          • I want to use just pure bash

            – zblash
            Apr 14 at 17:20
















          I want to use just pure bash

          – zblash
          Apr 14 at 17:20





          I want to use just pure bash

          – zblash
          Apr 14 at 17:20










          zblash is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          zblash is a new contributor. Be nice, and check out our Code of Conduct.












          zblash is a new contributor. Be nice, and check out our Code of Conduct.











          zblash is a new contributor. Be nice, and check out our Code of Conduct.














          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f512437%2fcopy-and-rename-files-to-a-sequential-numbering-with-subdirectories%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

          Cannot Extend partition with GParted The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsCan't increase partition size with GParted?GParted doesn't recognize the unallocated space after my current partitionWhat is the best way to add unallocated space located before to Ubuntu 12.04 partition with GParted live?I can't figure out how to extend my Arch home partition into free spaceGparted Linux Mint 18.1 issueTrying to extend but swap partition is showing as Unknown in Gparted, shows proper from fdiskRearrange partitions in gparted to extend a partitionUnable to extend partition even though unallocated space is next to it using GPartedAllocate free space to root partitiongparted: how to merge unallocated space with a partition

          Marilyn Monroe Ny fiainany manokana | Jereo koa | Meny fitetezanafanitarana azy.