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;








-1















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.










share|improve this question


























  • 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

















-1















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.










share|improve this question


























  • 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













-1












-1








-1








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.










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















  • 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












1 Answer
1






active

oldest

votes


















1














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 /?





share|improve this answer



























  • 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










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
);



);













draft saved

draft discarded


















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









1














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 /?





share|improve this answer



























  • 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















1














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 /?





share|improve this answer



























  • 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













1












1








1







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 /?





share|improve this answer















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 /?






share|improve this answer














share|improve this answer



share|improve this answer








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

















  • 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








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.



















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현