Batch File to delete folders who don't have a specific wordHow 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 fileHow can I echo a newline in a batch file?Windows batch files: .bat vs .cmd?How to sleep for five seconds in a batch file/cmdBatch based file/folder creationDelete zero sized files from a specified folder using batch fileWhat does the code mean? (Deleting files and sub folders in a folder with a batch file)how to delete files using a batch file
Designing a prison for a telekinetic race
Reducing contention in thread-safe LruCache
Meaning and structure of headline "Hair it is: A List of ..."
Build a mob of suspiciously happy lenny faces ( ͡° ͜ʖ ͡°)
What should I do with the stock I own if I anticipate there will be a recession?
Why should P.I be willing to write strong LOR even if that means losing a undergraduate from his/her lab?
Radix2 Fast Fourier Transform implemented in C++
What allows us to use imaginary numbers?
Can 'in-' mean both 'in' and 'no'?
Tabularx with hline and overrightarrow vertical spacing
Is "stainless" a bulk or a surface property of stainless steel?
Number of matrices with bounded products of rows and columns
Best model for precedence constraints within scheduling problem
Earliest evidence of objects intended for future archaeologists?
Are unaudited server logs admissible in a court of law?
What is bodily formation? Does it refer to the breath or the body?
Levenshtein Neighbours
Playing a fast but quiet Alberti bass
Installing certbot - error - "nothing provides pyparsing"
9 hrs long transit in DEL
Output with the same length always
What was the intention with the Commodore 128?
Why should I pay for an SSL certificate?
Do banks' profitability really suffer under low interest rates
Batch File to delete folders who don't have a specific word
How 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 fileHow can I echo a newline in a batch file?Windows batch files: .bat vs .cmd?How to sleep for five seconds in a batch file/cmdBatch based file/folder creationDelete zero sized files from a specified folder using batch fileWhat does the code mean? (Deleting files and sub folders in a folder with a batch file)how to delete files using a batch file
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a Movie folder that contains the following structure:
C:MoviesMovie Title 1
C:MoviesMovie Title 2
C:MoviesMovie Title 3 xyz
C:MoviesMovie Title 4 xyz
C:MoviesMovie Title 5
C:MoviesMovie Title 6 xyz
C:MoviesMovie Title 7.avi
C:MoviesMovie Title 8.mp4
What I'm looking for, is a batch file that I can run over a task scheduler, to delete all the folders (and is content), that don't have the word xyz
, and in addition also other file types in Movies folder, e.g.:
C:MoviesMovie Title 7.avi
C:MoviesMovie Title 8.mp4
Thus, as a result of the batch file execution, I would only have:
C:MoviesMovie Title 3 xyz
C:MoviesMovie Title 4 xyz
C:MoviesMovie Title 6 xyz
What I have so far is this code:
set folder="C:Movies"
cd /d %folder%
for /F "delims=" %%i in ('dir /b') do (rmdir *.* /q || del *.* /q)
But this, only delete files in the folder movies, doesn't delete folders who don't have the specific word as I mentioned above.
batch-file
add a comment |
I have a Movie folder that contains the following structure:
C:MoviesMovie Title 1
C:MoviesMovie Title 2
C:MoviesMovie Title 3 xyz
C:MoviesMovie Title 4 xyz
C:MoviesMovie Title 5
C:MoviesMovie Title 6 xyz
C:MoviesMovie Title 7.avi
C:MoviesMovie Title 8.mp4
What I'm looking for, is a batch file that I can run over a task scheduler, to delete all the folders (and is content), that don't have the word xyz
, and in addition also other file types in Movies folder, e.g.:
C:MoviesMovie Title 7.avi
C:MoviesMovie Title 8.mp4
Thus, as a result of the batch file execution, I would only have:
C:MoviesMovie Title 3 xyz
C:MoviesMovie Title 4 xyz
C:MoviesMovie Title 6 xyz
What I have so far is this code:
set folder="C:Movies"
cd /d %folder%
for /F "delims=" %%i in ('dir /b') do (rmdir *.* /q || del *.* /q)
But this, only delete files in the folder movies, doesn't delete folders who don't have the specific word as I mentioned above.
batch-file
What did you try already?
– Dominique
Mar 27 at 12:26
there are a few ways, but you need to at least show what you have tried before I can really post an answer for you.
– Gerhard Barnard
Mar 27 at 12:33
add a comment |
I have a Movie folder that contains the following structure:
C:MoviesMovie Title 1
C:MoviesMovie Title 2
C:MoviesMovie Title 3 xyz
C:MoviesMovie Title 4 xyz
C:MoviesMovie Title 5
C:MoviesMovie Title 6 xyz
C:MoviesMovie Title 7.avi
C:MoviesMovie Title 8.mp4
What I'm looking for, is a batch file that I can run over a task scheduler, to delete all the folders (and is content), that don't have the word xyz
, and in addition also other file types in Movies folder, e.g.:
C:MoviesMovie Title 7.avi
C:MoviesMovie Title 8.mp4
Thus, as a result of the batch file execution, I would only have:
C:MoviesMovie Title 3 xyz
C:MoviesMovie Title 4 xyz
C:MoviesMovie Title 6 xyz
What I have so far is this code:
set folder="C:Movies"
cd /d %folder%
for /F "delims=" %%i in ('dir /b') do (rmdir *.* /q || del *.* /q)
But this, only delete files in the folder movies, doesn't delete folders who don't have the specific word as I mentioned above.
batch-file
I have a Movie folder that contains the following structure:
C:MoviesMovie Title 1
C:MoviesMovie Title 2
C:MoviesMovie Title 3 xyz
C:MoviesMovie Title 4 xyz
C:MoviesMovie Title 5
C:MoviesMovie Title 6 xyz
C:MoviesMovie Title 7.avi
C:MoviesMovie Title 8.mp4
What I'm looking for, is a batch file that I can run over a task scheduler, to delete all the folders (and is content), that don't have the word xyz
, and in addition also other file types in Movies folder, e.g.:
C:MoviesMovie Title 7.avi
C:MoviesMovie Title 8.mp4
Thus, as a result of the batch file execution, I would only have:
C:MoviesMovie Title 3 xyz
C:MoviesMovie Title 4 xyz
C:MoviesMovie Title 6 xyz
What I have so far is this code:
set folder="C:Movies"
cd /d %folder%
for /F "delims=" %%i in ('dir /b') do (rmdir *.* /q || del *.* /q)
But this, only delete files in the folder movies, doesn't delete folders who don't have the specific word as I mentioned above.
batch-file
batch-file
edited Mar 27 at 13:40
user11266097
asked Mar 27 at 12:05
user11266097user11266097
11 bronze badge
11 bronze badge
What did you try already?
– Dominique
Mar 27 at 12:26
there are a few ways, but you need to at least show what you have tried before I can really post an answer for you.
– Gerhard Barnard
Mar 27 at 12:33
add a comment |
What did you try already?
– Dominique
Mar 27 at 12:26
there are a few ways, but you need to at least show what you have tried before I can really post an answer for you.
– Gerhard Barnard
Mar 27 at 12:33
What did you try already?
– Dominique
Mar 27 at 12:26
What did you try already?
– Dominique
Mar 27 at 12:26
there are a few ways, but you need to at least show what you have tried before I can really post an answer for you.
– Gerhard Barnard
Mar 27 at 12:33
there are a few ways, but you need to at least show what you have tried before I can really post an answer for you.
– Gerhard Barnard
Mar 27 at 12:33
add a comment |
1 Answer
1
active
oldest
votes
You can use many methods.. for one, you could use findstr
and run both del
and rmdir
on the files, without having to check what they are and simply redirect to nul
.
@echo off
for /f "delims=" %%i in ('dir /b C:Movies ^| findstr /vi "xyz"') do (
del /Q "%%i">nul
rmdir /Q/S "%%i">nul
)
Feel free to read up on the above commands from cmd.exe
findstr /?
for /?
if /?
It worked! :) Thanks for the help
– user11266097
Mar 27 at 14:09
1
If it worked, you should throw Gerhard a bone by accepting this as the accepted answer ;)
– Señor CMasMas
Mar 27 at 15:13
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%2f55376776%2fbatch-file-to-delete-folders-who-dont-have-a-specific-word%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 use many methods.. for one, you could use findstr
and run both del
and rmdir
on the files, without having to check what they are and simply redirect to nul
.
@echo off
for /f "delims=" %%i in ('dir /b C:Movies ^| findstr /vi "xyz"') do (
del /Q "%%i">nul
rmdir /Q/S "%%i">nul
)
Feel free to read up on the above commands from cmd.exe
findstr /?
for /?
if /?
It worked! :) Thanks for the help
– user11266097
Mar 27 at 14:09
1
If it worked, you should throw Gerhard a bone by accepting this as the accepted answer ;)
– Señor CMasMas
Mar 27 at 15:13
add a comment |
You can use many methods.. for one, you could use findstr
and run both del
and rmdir
on the files, without having to check what they are and simply redirect to nul
.
@echo off
for /f "delims=" %%i in ('dir /b C:Movies ^| findstr /vi "xyz"') do (
del /Q "%%i">nul
rmdir /Q/S "%%i">nul
)
Feel free to read up on the above commands from cmd.exe
findstr /?
for /?
if /?
It worked! :) Thanks for the help
– user11266097
Mar 27 at 14:09
1
If it worked, you should throw Gerhard a bone by accepting this as the accepted answer ;)
– Señor CMasMas
Mar 27 at 15:13
add a comment |
You can use many methods.. for one, you could use findstr
and run both del
and rmdir
on the files, without having to check what they are and simply redirect to nul
.
@echo off
for /f "delims=" %%i in ('dir /b C:Movies ^| findstr /vi "xyz"') do (
del /Q "%%i">nul
rmdir /Q/S "%%i">nul
)
Feel free to read up on the above commands from cmd.exe
findstr /?
for /?
if /?
You can use many methods.. for one, you could use findstr
and run both del
and rmdir
on the files, without having to check what they are and simply redirect to nul
.
@echo off
for /f "delims=" %%i in ('dir /b C:Movies ^| findstr /vi "xyz"') do (
del /Q "%%i">nul
rmdir /Q/S "%%i">nul
)
Feel free to read up on the above commands from cmd.exe
findstr /?
for /?
if /?
edited Mar 27 at 14:06
answered Mar 27 at 12:53
Gerhard BarnardGerhard Barnard
10.4k3 gold badges14 silver badges33 bronze badges
10.4k3 gold badges14 silver badges33 bronze badges
It worked! :) Thanks for the help
– user11266097
Mar 27 at 14:09
1
If it worked, you should throw Gerhard a bone by accepting this as the accepted answer ;)
– Señor CMasMas
Mar 27 at 15:13
add a comment |
It worked! :) Thanks for the help
– user11266097
Mar 27 at 14:09
1
If it worked, you should throw Gerhard a bone by accepting this as the accepted answer ;)
– Señor CMasMas
Mar 27 at 15:13
It worked! :) Thanks for the help
– user11266097
Mar 27 at 14:09
It worked! :) Thanks for the help
– user11266097
Mar 27 at 14:09
1
1
If it worked, you should throw Gerhard a bone by accepting this as the accepted answer ;)
– Señor CMasMas
Mar 27 at 15:13
If it worked, you should throw Gerhard a bone by accepting this as the accepted answer ;)
– Señor CMasMas
Mar 27 at 15:13
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
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%2f55376776%2fbatch-file-to-delete-folders-who-dont-have-a-specific-word%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
What did you try already?
– Dominique
Mar 27 at 12:26
there are a few ways, but you need to at least show what you have tried before I can really post an answer for you.
– Gerhard Barnard
Mar 27 at 12:33