Remove multiple copies of folder that starts with same name using batch-file Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceHow can I pass arguments to a batch file?Batch file to delete files older than N daysSplit long commands in multiple lines through Windows batch fileWindows batch files: .bat vs .cmd?How to run multiple .BAT files within a .BAT fileHow to verify if a file exists in a batch file?What is the current directory in a batch file?copying all contents of folder to another folder using batch file?Batch file. Delete all files and folders in a directoryHow do I find all files containing specific text on Linux?
What's the difference between (size_t)-1 and ~0?
Determine whether f is a function, an injection, a surjection
How can players take actions together that are impossible otherwise?
Was credit for the black hole image misattributed?
I'm having difficulty getting my players to do stuff in a sandbox campaign
When is phishing education going too far?
Antler Helmet: Can it work?
Estimate capacitor parameters
What can I do if my MacBook isn’t charging but already ran out?
How to say that you spent the night with someone, you were only sleeping and nothing else?
Simulating Exploding Dice
Geometric mean and geometric standard deviation
Is there a service that would inform me whenever a new direct route is scheduled from a given airport?
If I can make up priors, why can't I make up posteriors?
How to market an anarchic city as a tourism spot to people living in civilized areas?
Are my PIs rude or am I just being too sensitive?
Cold is to Refrigerator as warm is to?
3 doors, three guards, one stone
New Order #5: where Fibonacci and Beatty meet at Wythoff
Complexity of many constant time steps with occasional logarithmic steps
Mortgage adviser recommends a longer term than necessary combined with overpayments
What do you call a plan that's an alternative plan in case your initial plan fails?
Why is "Captain Marvel" translated as male in Portugal?
Area of a 2D convex hull
Remove multiple copies of folder that starts with same name using batch-file
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experienceHow can I pass arguments to a batch file?Batch file to delete files older than N daysSplit long commands in multiple lines through Windows batch fileWindows batch files: .bat vs .cmd?How to run multiple .BAT files within a .BAT fileHow to verify if a file exists in a batch file?What is the current directory in a batch file?copying all contents of folder to another folder using batch file?Batch file. Delete all files and folders in a directoryHow do I find all files containing specific text on Linux?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
My DESKTOP contain copies of 'CEEMEA EMEA' folder i.e.
EMEA CEEMEA
EMEA CEEMEA - Copy
EMEA CEEMEA - Copy (2)
EMEA CEEMEA - Copy (3)
and so on
I want to delete all folders that starts with EMEA CEEMEA as file name using CMD
or batch-file.
rd /s /q "%CD%NEW FOLDER*"
but above command not doing anything. how does it work?
batch-file cmd directory
add a comment |
My DESKTOP contain copies of 'CEEMEA EMEA' folder i.e.
EMEA CEEMEA
EMEA CEEMEA - Copy
EMEA CEEMEA - Copy (2)
EMEA CEEMEA - Copy (3)
and so on
I want to delete all folders that starts with EMEA CEEMEA as file name using CMD
or batch-file.
rd /s /q "%CD%NEW FOLDER*"
but above command not doing anything. how does it work?
batch-file cmd directory
add a comment |
My DESKTOP contain copies of 'CEEMEA EMEA' folder i.e.
EMEA CEEMEA
EMEA CEEMEA - Copy
EMEA CEEMEA - Copy (2)
EMEA CEEMEA - Copy (3)
and so on
I want to delete all folders that starts with EMEA CEEMEA as file name using CMD
or batch-file.
rd /s /q "%CD%NEW FOLDER*"
but above command not doing anything. how does it work?
batch-file cmd directory
My DESKTOP contain copies of 'CEEMEA EMEA' folder i.e.
EMEA CEEMEA
EMEA CEEMEA - Copy
EMEA CEEMEA - Copy (2)
EMEA CEEMEA - Copy (3)
and so on
I want to delete all folders that starts with EMEA CEEMEA as file name using CMD
or batch-file.
rd /s /q "%CD%NEW FOLDER*"
but above command not doing anything. how does it work?
batch-file cmd directory
batch-file cmd directory
edited Mar 25 at 7:58
Ibn e Ashiq
asked Mar 22 at 7:43
Ibn e AshiqIbn e Ashiq
3221620
3221620
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can do this using a For
loop with its /D
option:
For /D %A In ("%UserProfile%DesktopEMEA CEEMEA*")Do @RD/S/Q "%A"
As you've updated your question to include batch-file, you'd change the command to this from one:
For /D %%A In ("%UserProfile%DesktopEMEA CEEMEA*")Do @RD/S/Q "%%A"
1
I'd prefer that you first take a look at the usage information for both of the commands used. Open a Command Prompt window and enterFor /?
, and read its content, paying additional note to its/D
option. Next repeat the process usingRD /?
. After you've read them, if you still have any questions pertaining to this particular line of code, post back, and we'll see if we can help explain. Essentially it looks for directories, matching the wilcarded fileset in parentheses, and outputs each match, one at a time , as the metavariable%A
, which is subsequently used in theDo
command,RD
.
– Compo
Mar 23 at 16:52
actually I need to use thisFor /D %A In ("%CD%EMEA CEEMEA*")Do @RD/S/Q "%A"
in.bat
file and it does nothing.. is there anything I could change ??
– Ibn e Ashiq
Mar 25 at 6:09
1
It all depends upon where your batch file is located or what your current working directory is at the time the line is ran. You statedMy DESKTOP
, so I provided, the location for that. One thing is for sure, you do not need the%CD%
part, because any location which is not a fully qualified path will be taken as relative to the current directory.
– Compo
Mar 25 at 8:20
you are right aboutDesktop
. Problem with my command was I did not use %% percentage, nowFor /D %%A In ("%CD%EMEA CEEMEA*")Do @RD/S/Q "%%A"
is working fine.
– Ibn e Ashiq
Mar 25 at 8:26
I updated my answer, when I noticed that you'd modified your question to include the batch file requirement.
– Compo
Mar 25 at 8:28
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%2f55294961%2fremove-multiple-copies-of-folder-that-starts-with-same-name-using-batch-file%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
You can do this using a For
loop with its /D
option:
For /D %A In ("%UserProfile%DesktopEMEA CEEMEA*")Do @RD/S/Q "%A"
As you've updated your question to include batch-file, you'd change the command to this from one:
For /D %%A In ("%UserProfile%DesktopEMEA CEEMEA*")Do @RD/S/Q "%%A"
1
I'd prefer that you first take a look at the usage information for both of the commands used. Open a Command Prompt window and enterFor /?
, and read its content, paying additional note to its/D
option. Next repeat the process usingRD /?
. After you've read them, if you still have any questions pertaining to this particular line of code, post back, and we'll see if we can help explain. Essentially it looks for directories, matching the wilcarded fileset in parentheses, and outputs each match, one at a time , as the metavariable%A
, which is subsequently used in theDo
command,RD
.
– Compo
Mar 23 at 16:52
actually I need to use thisFor /D %A In ("%CD%EMEA CEEMEA*")Do @RD/S/Q "%A"
in.bat
file and it does nothing.. is there anything I could change ??
– Ibn e Ashiq
Mar 25 at 6:09
1
It all depends upon where your batch file is located or what your current working directory is at the time the line is ran. You statedMy DESKTOP
, so I provided, the location for that. One thing is for sure, you do not need the%CD%
part, because any location which is not a fully qualified path will be taken as relative to the current directory.
– Compo
Mar 25 at 8:20
you are right aboutDesktop
. Problem with my command was I did not use %% percentage, nowFor /D %%A In ("%CD%EMEA CEEMEA*")Do @RD/S/Q "%%A"
is working fine.
– Ibn e Ashiq
Mar 25 at 8:26
I updated my answer, when I noticed that you'd modified your question to include the batch file requirement.
– Compo
Mar 25 at 8:28
add a comment |
You can do this using a For
loop with its /D
option:
For /D %A In ("%UserProfile%DesktopEMEA CEEMEA*")Do @RD/S/Q "%A"
As you've updated your question to include batch-file, you'd change the command to this from one:
For /D %%A In ("%UserProfile%DesktopEMEA CEEMEA*")Do @RD/S/Q "%%A"
1
I'd prefer that you first take a look at the usage information for both of the commands used. Open a Command Prompt window and enterFor /?
, and read its content, paying additional note to its/D
option. Next repeat the process usingRD /?
. After you've read them, if you still have any questions pertaining to this particular line of code, post back, and we'll see if we can help explain. Essentially it looks for directories, matching the wilcarded fileset in parentheses, and outputs each match, one at a time , as the metavariable%A
, which is subsequently used in theDo
command,RD
.
– Compo
Mar 23 at 16:52
actually I need to use thisFor /D %A In ("%CD%EMEA CEEMEA*")Do @RD/S/Q "%A"
in.bat
file and it does nothing.. is there anything I could change ??
– Ibn e Ashiq
Mar 25 at 6:09
1
It all depends upon where your batch file is located or what your current working directory is at the time the line is ran. You statedMy DESKTOP
, so I provided, the location for that. One thing is for sure, you do not need the%CD%
part, because any location which is not a fully qualified path will be taken as relative to the current directory.
– Compo
Mar 25 at 8:20
you are right aboutDesktop
. Problem with my command was I did not use %% percentage, nowFor /D %%A In ("%CD%EMEA CEEMEA*")Do @RD/S/Q "%%A"
is working fine.
– Ibn e Ashiq
Mar 25 at 8:26
I updated my answer, when I noticed that you'd modified your question to include the batch file requirement.
– Compo
Mar 25 at 8:28
add a comment |
You can do this using a For
loop with its /D
option:
For /D %A In ("%UserProfile%DesktopEMEA CEEMEA*")Do @RD/S/Q "%A"
As you've updated your question to include batch-file, you'd change the command to this from one:
For /D %%A In ("%UserProfile%DesktopEMEA CEEMEA*")Do @RD/S/Q "%%A"
You can do this using a For
loop with its /D
option:
For /D %A In ("%UserProfile%DesktopEMEA CEEMEA*")Do @RD/S/Q "%A"
As you've updated your question to include batch-file, you'd change the command to this from one:
For /D %%A In ("%UserProfile%DesktopEMEA CEEMEA*")Do @RD/S/Q "%%A"
edited Mar 25 at 8:26
answered Mar 22 at 19:32
CompoCompo
17.2k31027
17.2k31027
1
I'd prefer that you first take a look at the usage information for both of the commands used. Open a Command Prompt window and enterFor /?
, and read its content, paying additional note to its/D
option. Next repeat the process usingRD /?
. After you've read them, if you still have any questions pertaining to this particular line of code, post back, and we'll see if we can help explain. Essentially it looks for directories, matching the wilcarded fileset in parentheses, and outputs each match, one at a time , as the metavariable%A
, which is subsequently used in theDo
command,RD
.
– Compo
Mar 23 at 16:52
actually I need to use thisFor /D %A In ("%CD%EMEA CEEMEA*")Do @RD/S/Q "%A"
in.bat
file and it does nothing.. is there anything I could change ??
– Ibn e Ashiq
Mar 25 at 6:09
1
It all depends upon where your batch file is located or what your current working directory is at the time the line is ran. You statedMy DESKTOP
, so I provided, the location for that. One thing is for sure, you do not need the%CD%
part, because any location which is not a fully qualified path will be taken as relative to the current directory.
– Compo
Mar 25 at 8:20
you are right aboutDesktop
. Problem with my command was I did not use %% percentage, nowFor /D %%A In ("%CD%EMEA CEEMEA*")Do @RD/S/Q "%%A"
is working fine.
– Ibn e Ashiq
Mar 25 at 8:26
I updated my answer, when I noticed that you'd modified your question to include the batch file requirement.
– Compo
Mar 25 at 8:28
add a comment |
1
I'd prefer that you first take a look at the usage information for both of the commands used. Open a Command Prompt window and enterFor /?
, and read its content, paying additional note to its/D
option. Next repeat the process usingRD /?
. After you've read them, if you still have any questions pertaining to this particular line of code, post back, and we'll see if we can help explain. Essentially it looks for directories, matching the wilcarded fileset in parentheses, and outputs each match, one at a time , as the metavariable%A
, which is subsequently used in theDo
command,RD
.
– Compo
Mar 23 at 16:52
actually I need to use thisFor /D %A In ("%CD%EMEA CEEMEA*")Do @RD/S/Q "%A"
in.bat
file and it does nothing.. is there anything I could change ??
– Ibn e Ashiq
Mar 25 at 6:09
1
It all depends upon where your batch file is located or what your current working directory is at the time the line is ran. You statedMy DESKTOP
, so I provided, the location for that. One thing is for sure, you do not need the%CD%
part, because any location which is not a fully qualified path will be taken as relative to the current directory.
– Compo
Mar 25 at 8:20
you are right aboutDesktop
. Problem with my command was I did not use %% percentage, nowFor /D %%A In ("%CD%EMEA CEEMEA*")Do @RD/S/Q "%%A"
is working fine.
– Ibn e Ashiq
Mar 25 at 8:26
I updated my answer, when I noticed that you'd modified your question to include the batch file requirement.
– Compo
Mar 25 at 8:28
1
1
I'd prefer that you first take a look at the usage information for both of the commands used. Open a Command Prompt window and enter
For /?
, and read its content, paying additional note to its /D
option. Next repeat the process using RD /?
. After you've read them, if you still have any questions pertaining to this particular line of code, post back, and we'll see if we can help explain. Essentially it looks for directories, matching the wilcarded fileset in parentheses, and outputs each match, one at a time , as the metavariable %A
, which is subsequently used in the Do
command, RD
.– Compo
Mar 23 at 16:52
I'd prefer that you first take a look at the usage information for both of the commands used. Open a Command Prompt window and enter
For /?
, and read its content, paying additional note to its /D
option. Next repeat the process using RD /?
. After you've read them, if you still have any questions pertaining to this particular line of code, post back, and we'll see if we can help explain. Essentially it looks for directories, matching the wilcarded fileset in parentheses, and outputs each match, one at a time , as the metavariable %A
, which is subsequently used in the Do
command, RD
.– Compo
Mar 23 at 16:52
actually I need to use this
For /D %A In ("%CD%EMEA CEEMEA*")Do @RD/S/Q "%A"
in .bat
file and it does nothing.. is there anything I could change ??– Ibn e Ashiq
Mar 25 at 6:09
actually I need to use this
For /D %A In ("%CD%EMEA CEEMEA*")Do @RD/S/Q "%A"
in .bat
file and it does nothing.. is there anything I could change ??– Ibn e Ashiq
Mar 25 at 6:09
1
1
It all depends upon where your batch file is located or what your current working directory is at the time the line is ran. You stated
My DESKTOP
, so I provided, the location for that. One thing is for sure, you do not need the %CD%
part, because any location which is not a fully qualified path will be taken as relative to the current directory.– Compo
Mar 25 at 8:20
It all depends upon where your batch file is located or what your current working directory is at the time the line is ran. You stated
My DESKTOP
, so I provided, the location for that. One thing is for sure, you do not need the %CD%
part, because any location which is not a fully qualified path will be taken as relative to the current directory.– Compo
Mar 25 at 8:20
you are right about
Desktop
. Problem with my command was I did not use %% percentage, now For /D %%A In ("%CD%EMEA CEEMEA*")Do @RD/S/Q "%%A"
is working fine.– Ibn e Ashiq
Mar 25 at 8:26
you are right about
Desktop
. Problem with my command was I did not use %% percentage, now For /D %%A In ("%CD%EMEA CEEMEA*")Do @RD/S/Q "%%A"
is working fine.– Ibn e Ashiq
Mar 25 at 8:26
I updated my answer, when I noticed that you'd modified your question to include the batch file requirement.
– Compo
Mar 25 at 8:28
I updated my answer, when I noticed that you'd modified your question to include the batch file requirement.
– Compo
Mar 25 at 8:28
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%2f55294961%2fremove-multiple-copies-of-folder-that-starts-with-same-name-using-batch-file%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