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;
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
New contributor
add a comment |
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
New contributor
add a comment |
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
New contributor
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
shell-script rename
New contributor
New contributor
New contributor
asked Apr 14 at 16:34
zblashzblash
11
11
New contributor
New contributor
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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 ]
.
I want to use just pure bash
– zblash
Apr 14 at 17:20
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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 ]
.
I want to use just pure bash
– zblash
Apr 14 at 17:20
add a comment |
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 ]
.
I want to use just pure bash
– zblash
Apr 14 at 17:20
add a comment |
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 ]
.
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 ]
.
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
add a comment |
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
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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