Merge multiple directories into one, named according to the common directory prefix
I made a batch file to rename directories to the string preceding -
, but now there is a problem:
Let's say, for example, I had these folders:
Naruto - 480p
Naruto - 720p
Naruto - 1080p
I want to have only one directory, named Naruto
, which contains the content of those three directories.
I use this batch file:
for /f "tokens=1*delims=-" %%a in ('dir /b "*-*.*"') do ren "%%a-%%b" "%%a%%~xb"
…but even with the batch file the resultant directories seem to be:
Naruto
Naruto - 720p
Naruto - 1080p
How can I merge the three directories into one which will be named Naruto
?
batch-file for-loop directory
add a comment |
I made a batch file to rename directories to the string preceding -
, but now there is a problem:
Let's say, for example, I had these folders:
Naruto - 480p
Naruto - 720p
Naruto - 1080p
I want to have only one directory, named Naruto
, which contains the content of those three directories.
I use this batch file:
for /f "tokens=1*delims=-" %%a in ('dir /b "*-*.*"') do ren "%%a-%%b" "%%a%%~xb"
…but even with the batch file the resultant directories seem to be:
Naruto
Naruto - 720p
Naruto - 1080p
How can I merge the three directories into one which will be named Naruto
?
batch-file for-loop directory
You cannot rename three directories in one location to the same name, for the same reason you cannot have three files in one directory with the same name and extension! You need toren
ame,move
files andr
emoved
irectories, orm
aked
irectory,move
files andr
emoved
irectories.
– Compo
Nov 21 '18 at 16:41
There is no.
character in your directory names either!
– Compo
Nov 21 '18 at 17:17
You should also use the/AD
option so that theDIR
command only lists folders.
– Squashman
Nov 21 '18 at 17:18
add a comment |
I made a batch file to rename directories to the string preceding -
, but now there is a problem:
Let's say, for example, I had these folders:
Naruto - 480p
Naruto - 720p
Naruto - 1080p
I want to have only one directory, named Naruto
, which contains the content of those three directories.
I use this batch file:
for /f "tokens=1*delims=-" %%a in ('dir /b "*-*.*"') do ren "%%a-%%b" "%%a%%~xb"
…but even with the batch file the resultant directories seem to be:
Naruto
Naruto - 720p
Naruto - 1080p
How can I merge the three directories into one which will be named Naruto
?
batch-file for-loop directory
I made a batch file to rename directories to the string preceding -
, but now there is a problem:
Let's say, for example, I had these folders:
Naruto - 480p
Naruto - 720p
Naruto - 1080p
I want to have only one directory, named Naruto
, which contains the content of those three directories.
I use this batch file:
for /f "tokens=1*delims=-" %%a in ('dir /b "*-*.*"') do ren "%%a-%%b" "%%a%%~xb"
…but even with the batch file the resultant directories seem to be:
Naruto
Naruto - 720p
Naruto - 1080p
How can I merge the three directories into one which will be named Naruto
?
batch-file for-loop directory
batch-file for-loop directory
edited Nov 21 '18 at 18:35
Compo
17k3927
17k3927
asked Nov 21 '18 at 16:18
MELEgrane DellabiMELEgrane Dellabi
14
14
You cannot rename three directories in one location to the same name, for the same reason you cannot have three files in one directory with the same name and extension! You need toren
ame,move
files andr
emoved
irectories, orm
aked
irectory,move
files andr
emoved
irectories.
– Compo
Nov 21 '18 at 16:41
There is no.
character in your directory names either!
– Compo
Nov 21 '18 at 17:17
You should also use the/AD
option so that theDIR
command only lists folders.
– Squashman
Nov 21 '18 at 17:18
add a comment |
You cannot rename three directories in one location to the same name, for the same reason you cannot have three files in one directory with the same name and extension! You need toren
ame,move
files andr
emoved
irectories, orm
aked
irectory,move
files andr
emoved
irectories.
– Compo
Nov 21 '18 at 16:41
There is no.
character in your directory names either!
– Compo
Nov 21 '18 at 17:17
You should also use the/AD
option so that theDIR
command only lists folders.
– Squashman
Nov 21 '18 at 17:18
You cannot rename three directories in one location to the same name, for the same reason you cannot have three files in one directory with the same name and extension! You need to
ren
ame, move
files and r
emove d
irectories, or m
ake d
irectory, move
files and r
emove d
irectories.– Compo
Nov 21 '18 at 16:41
You cannot rename three directories in one location to the same name, for the same reason you cannot have three files in one directory with the same name and extension! You need to
ren
ame, move
files and r
emove d
irectories, or m
ake d
irectory, move
files and r
emove d
irectories.– Compo
Nov 21 '18 at 16:41
There is no
.
character in your directory names either!– Compo
Nov 21 '18 at 17:17
There is no
.
character in your directory names either!– Compo
Nov 21 '18 at 17:17
You should also use the
/AD
option so that the DIR
command only lists folders.– Squashman
Nov 21 '18 at 17:18
You should also use the
/AD
option so that the DIR
command only lists folders.– Squashman
Nov 21 '18 at 17:18
add a comment |
1 Answer
1
active
oldest
votes
If I understood well, you want to merge these three folders. This is not possible in batchfile language, so you need to move content of the two folders into one, remove them and rename the remaining folder. This is a way you can do it:
@echo off
:: Batch script that merges 3 folders into one!
:: We assume that these 3 folders are located in C: .
for /R C:Naruto-480p %%a IN (*.*) do move "%%a" C:Naruto-1080p
for /R C:Naruto-720p %%b IN (*.*) do move "%%b" C:Naruto-1080p
rd Naruto-480p Naruto-720p
rename Naruto-1080p Naruto
Now let's break out the batch file program:
Lines starting with ::
are comments, they are ignored. In fact, they are invalid labels.
for /R C:Naruto-480p %%a IN (*.*) do @move "%%a" C:Naruto-1080p
and for /R C:Naruto-720p %%b IN (*.*) do @move "%%b" C:Naruto-1080p
. for
is a loop as you already know. The /R
option tells the loop to run through all the subfolders of the folder specified in the start (C:Naturo-480p and C:Naruto-720p respectively). IN (*.*)
means to process ALL files found and, finally, move each file.
rd Naruto-480p Naruto-720p
removes folders Naruto-480p
and Naruto-720p
.
rename Naruto-1080p Naruto
renames the folder.
I hope that this helps you exit your trouble :-).
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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
});
}
});
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%2fstackoverflow.com%2fquestions%2f53416328%2fmerge-multiple-directories-into-one-named-according-to-the-common-directory-pre%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
If I understood well, you want to merge these three folders. This is not possible in batchfile language, so you need to move content of the two folders into one, remove them and rename the remaining folder. This is a way you can do it:
@echo off
:: Batch script that merges 3 folders into one!
:: We assume that these 3 folders are located in C: .
for /R C:Naruto-480p %%a IN (*.*) do move "%%a" C:Naruto-1080p
for /R C:Naruto-720p %%b IN (*.*) do move "%%b" C:Naruto-1080p
rd Naruto-480p Naruto-720p
rename Naruto-1080p Naruto
Now let's break out the batch file program:
Lines starting with ::
are comments, they are ignored. In fact, they are invalid labels.
for /R C:Naruto-480p %%a IN (*.*) do @move "%%a" C:Naruto-1080p
and for /R C:Naruto-720p %%b IN (*.*) do @move "%%b" C:Naruto-1080p
. for
is a loop as you already know. The /R
option tells the loop to run through all the subfolders of the folder specified in the start (C:Naturo-480p and C:Naruto-720p respectively). IN (*.*)
means to process ALL files found and, finally, move each file.
rd Naruto-480p Naruto-720p
removes folders Naruto-480p
and Naruto-720p
.
rename Naruto-1080p Naruto
renames the folder.
I hope that this helps you exit your trouble :-).
add a comment |
If I understood well, you want to merge these three folders. This is not possible in batchfile language, so you need to move content of the two folders into one, remove them and rename the remaining folder. This is a way you can do it:
@echo off
:: Batch script that merges 3 folders into one!
:: We assume that these 3 folders are located in C: .
for /R C:Naruto-480p %%a IN (*.*) do move "%%a" C:Naruto-1080p
for /R C:Naruto-720p %%b IN (*.*) do move "%%b" C:Naruto-1080p
rd Naruto-480p Naruto-720p
rename Naruto-1080p Naruto
Now let's break out the batch file program:
Lines starting with ::
are comments, they are ignored. In fact, they are invalid labels.
for /R C:Naruto-480p %%a IN (*.*) do @move "%%a" C:Naruto-1080p
and for /R C:Naruto-720p %%b IN (*.*) do @move "%%b" C:Naruto-1080p
. for
is a loop as you already know. The /R
option tells the loop to run through all the subfolders of the folder specified in the start (C:Naturo-480p and C:Naruto-720p respectively). IN (*.*)
means to process ALL files found and, finally, move each file.
rd Naruto-480p Naruto-720p
removes folders Naruto-480p
and Naruto-720p
.
rename Naruto-1080p Naruto
renames the folder.
I hope that this helps you exit your trouble :-).
add a comment |
If I understood well, you want to merge these three folders. This is not possible in batchfile language, so you need to move content of the two folders into one, remove them and rename the remaining folder. This is a way you can do it:
@echo off
:: Batch script that merges 3 folders into one!
:: We assume that these 3 folders are located in C: .
for /R C:Naruto-480p %%a IN (*.*) do move "%%a" C:Naruto-1080p
for /R C:Naruto-720p %%b IN (*.*) do move "%%b" C:Naruto-1080p
rd Naruto-480p Naruto-720p
rename Naruto-1080p Naruto
Now let's break out the batch file program:
Lines starting with ::
are comments, they are ignored. In fact, they are invalid labels.
for /R C:Naruto-480p %%a IN (*.*) do @move "%%a" C:Naruto-1080p
and for /R C:Naruto-720p %%b IN (*.*) do @move "%%b" C:Naruto-1080p
. for
is a loop as you already know. The /R
option tells the loop to run through all the subfolders of the folder specified in the start (C:Naturo-480p and C:Naruto-720p respectively). IN (*.*)
means to process ALL files found and, finally, move each file.
rd Naruto-480p Naruto-720p
removes folders Naruto-480p
and Naruto-720p
.
rename Naruto-1080p Naruto
renames the folder.
I hope that this helps you exit your trouble :-).
If I understood well, you want to merge these three folders. This is not possible in batchfile language, so you need to move content of the two folders into one, remove them and rename the remaining folder. This is a way you can do it:
@echo off
:: Batch script that merges 3 folders into one!
:: We assume that these 3 folders are located in C: .
for /R C:Naruto-480p %%a IN (*.*) do move "%%a" C:Naruto-1080p
for /R C:Naruto-720p %%b IN (*.*) do move "%%b" C:Naruto-1080p
rd Naruto-480p Naruto-720p
rename Naruto-1080p Naruto
Now let's break out the batch file program:
Lines starting with ::
are comments, they are ignored. In fact, they are invalid labels.
for /R C:Naruto-480p %%a IN (*.*) do @move "%%a" C:Naruto-1080p
and for /R C:Naruto-720p %%b IN (*.*) do @move "%%b" C:Naruto-1080p
. for
is a loop as you already know. The /R
option tells the loop to run through all the subfolders of the folder specified in the start (C:Naturo-480p and C:Naruto-720p respectively). IN (*.*)
means to process ALL files found and, finally, move each file.
rd Naruto-480p Naruto-720p
removes folders Naruto-480p
and Naruto-720p
.
rename Naruto-1080p Naruto
renames the folder.
I hope that this helps you exit your trouble :-).
edited Dec 25 '18 at 16:34
answered Nov 21 '18 at 17:50
double-beepdouble-beep
3,08141432
3,08141432
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- 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%2fstackoverflow.com%2fquestions%2f53416328%2fmerge-multiple-directories-into-one-named-according-to-the-common-directory-pre%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
You cannot rename three directories in one location to the same name, for the same reason you cannot have three files in one directory with the same name and extension! You need to
ren
ame,move
files andr
emoved
irectories, orm
aked
irectory,move
files andr
emoved
irectories.– Compo
Nov 21 '18 at 16:41
There is no
.
character in your directory names either!– Compo
Nov 21 '18 at 17:17
You should also use the
/AD
option so that theDIR
command only lists folders.– Squashman
Nov 21 '18 at 17:18