delete files in multiple subfolders with batchHow 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 fileBatch file. Delete all files and folders in a directoryHow to “comment-out” (add comment) in a batch/cmd?Batch file to delete subfolders in directory if all files is older than 3 daysWindows 7 batch file Copy all files from a folder structure to one folderbatch to delete subfolders of all subfolders
Hostile work environment after whistle-blowing on coworker and our boss. What do I do?
Implement the Thanos sorting algorithm
How can I get through very long and very dry, but also very useful technical documents when learning a new tool?
How can I replace every global instance of "x[2]" with "x_2"
What to do with wrong results in talks?
Minimal reference content
Personal Teleportation as a Weapon
How does it work when somebody invests in my business?
How does residential electricity work?
Increase performance creating Mandelbrot set in python
How do I rename a LINUX host without needing to reboot for the rename to take effect?
Print name if parameter passed to function
What defines a dissertation?
Hide Select Output from T-SQL
Can a monster with multiattack use this ability if they are missing a limb?
Bash method for viewing beginning and end of file
Why does John Bercow say “unlock” after reading out the results of a vote?
Can I use my Chinese passport to enter China after I acquired another citizenship?
Is there a problem with hiding "forgot password" until it's needed?
when is out of tune ok?
Your magic is very sketchy
Lay out the Carpet
Is a roofing delivery truck likely to crack my driveway slab?
What is the opposite of 'gravitas'?
delete files in multiple subfolders with batch
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 fileWindows batch files: .bat vs .cmd?How to run multiple .BAT files within a .BAT fileBatch file. Delete all files and folders in a directoryHow to “comment-out” (add comment) in a batch/cmd?Batch file to delete subfolders in directory if all files is older than 3 daysWindows 7 batch file Copy all files from a folder structure to one folderbatch to delete subfolders of all subfolders
I have a directory that looks like this
"C:salesclient1file1".
The client1 folder it's not static and can vary from client1 to client100 and each file inside the client folder can vary from file1 to file8.
I want to delete 4 speciefic files (eg file1, file3, file6 and file8) in every client folder, based on a mask (/m file1*) older than 7 days (d-7) using a batch.
So far every solution i have tried works for a specified directory
Thank you
batch-file cmd forfiles
add a comment |
I have a directory that looks like this
"C:salesclient1file1".
The client1 folder it's not static and can vary from client1 to client100 and each file inside the client folder can vary from file1 to file8.
I want to delete 4 speciefic files (eg file1, file3, file6 and file8) in every client folder, based on a mask (/m file1*) older than 7 days (d-7) using a batch.
So far every solution i have tried works for a specified directory
Thank you
batch-file cmd forfiles
2
Stack Overflow isn't a script writing service, what have you tried so far? edit your question to conntain your efforts in a Minimal, Complete, and Verifiable example.
– LotPings
Mar 7 at 12:09
Yes, if you noticed i said that every solution i tried worked only for a given path, my problem is changing subfolder without having to add a line for every folder.
– dammyware
Mar 7 at 13:52
1
This site expects you to provide the code you've tried which is causing the issue you're reporting. If you've tried more than one solution, it is important that you post those attempts and explain exactly what happens, which differs from yuor expectaitions, when you run each.
– Compo
Mar 7 at 14:06
add a comment |
I have a directory that looks like this
"C:salesclient1file1".
The client1 folder it's not static and can vary from client1 to client100 and each file inside the client folder can vary from file1 to file8.
I want to delete 4 speciefic files (eg file1, file3, file6 and file8) in every client folder, based on a mask (/m file1*) older than 7 days (d-7) using a batch.
So far every solution i have tried works for a specified directory
Thank you
batch-file cmd forfiles
I have a directory that looks like this
"C:salesclient1file1".
The client1 folder it's not static and can vary from client1 to client100 and each file inside the client folder can vary from file1 to file8.
I want to delete 4 speciefic files (eg file1, file3, file6 and file8) in every client folder, based on a mask (/m file1*) older than 7 days (d-7) using a batch.
So far every solution i have tried works for a specified directory
Thank you
batch-file cmd forfiles
batch-file cmd forfiles
edited Mar 7 at 14:19
LotPings
19.9k61633
19.9k61633
asked Mar 7 at 11:35
dammywaredammyware
27
27
2
Stack Overflow isn't a script writing service, what have you tried so far? edit your question to conntain your efforts in a Minimal, Complete, and Verifiable example.
– LotPings
Mar 7 at 12:09
Yes, if you noticed i said that every solution i tried worked only for a given path, my problem is changing subfolder without having to add a line for every folder.
– dammyware
Mar 7 at 13:52
1
This site expects you to provide the code you've tried which is causing the issue you're reporting. If you've tried more than one solution, it is important that you post those attempts and explain exactly what happens, which differs from yuor expectaitions, when you run each.
– Compo
Mar 7 at 14:06
add a comment |
2
Stack Overflow isn't a script writing service, what have you tried so far? edit your question to conntain your efforts in a Minimal, Complete, and Verifiable example.
– LotPings
Mar 7 at 12:09
Yes, if you noticed i said that every solution i tried worked only for a given path, my problem is changing subfolder without having to add a line for every folder.
– dammyware
Mar 7 at 13:52
1
This site expects you to provide the code you've tried which is causing the issue you're reporting. If you've tried more than one solution, it is important that you post those attempts and explain exactly what happens, which differs from yuor expectaitions, when you run each.
– Compo
Mar 7 at 14:06
2
2
Stack Overflow isn't a script writing service, what have you tried so far? edit your question to conntain your efforts in a Minimal, Complete, and Verifiable example.
– LotPings
Mar 7 at 12:09
Stack Overflow isn't a script writing service, what have you tried so far? edit your question to conntain your efforts in a Minimal, Complete, and Verifiable example.
– LotPings
Mar 7 at 12:09
Yes, if you noticed i said that every solution i tried worked only for a given path, my problem is changing subfolder without having to add a line for every folder.
– dammyware
Mar 7 at 13:52
Yes, if you noticed i said that every solution i tried worked only for a given path, my problem is changing subfolder without having to add a line for every folder.
– dammyware
Mar 7 at 13:52
1
1
This site expects you to provide the code you've tried which is causing the issue you're reporting. If you've tried more than one solution, it is important that you post those attempts and explain exactly what happens, which differs from yuor expectaitions, when you run each.
– Compo
Mar 7 at 14:06
This site expects you to provide the code you've tried which is causing the issue you're reporting. If you've tried more than one solution, it is important that you post those attempts and explain exactly what happens, which differs from yuor expectaitions, when you run each.
– Compo
Mar 7 at 14:06
add a comment |
1 Answer
1
active
oldest
votes
As your mask is a file and the @path will contain the file name,
you'll have to cd to the folder with .. appended to it @path..
So try:
forfiles /P C:Sales /S /M file1* /D -7 /C "cmd.exe /c @cd /D @path..&del file1 file3 file6 file8"
This command will also find file1 matching the criteria directly in C:Sales
A more consize solution using PowerShell
Get-ChildItem "C:SalesClient*file1" -File |
Where LastWriteTime -lt (Get-Date).Date.AddDays(-7)|
ForEach-Object
PushD $_.Directory
Remove-Object file[1368]
PopD
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%2f55042842%2fdelete-files-in-multiple-subfolders-with-batch%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
As your mask is a file and the @path will contain the file name,
you'll have to cd to the folder with .. appended to it @path..
So try:
forfiles /P C:Sales /S /M file1* /D -7 /C "cmd.exe /c @cd /D @path..&del file1 file3 file6 file8"
This command will also find file1 matching the criteria directly in C:Sales
A more consize solution using PowerShell
Get-ChildItem "C:SalesClient*file1" -File |
Where LastWriteTime -lt (Get-Date).Date.AddDays(-7)|
ForEach-Object
PushD $_.Directory
Remove-Object file[1368]
PopD
add a comment |
As your mask is a file and the @path will contain the file name,
you'll have to cd to the folder with .. appended to it @path..
So try:
forfiles /P C:Sales /S /M file1* /D -7 /C "cmd.exe /c @cd /D @path..&del file1 file3 file6 file8"
This command will also find file1 matching the criteria directly in C:Sales
A more consize solution using PowerShell
Get-ChildItem "C:SalesClient*file1" -File |
Where LastWriteTime -lt (Get-Date).Date.AddDays(-7)|
ForEach-Object
PushD $_.Directory
Remove-Object file[1368]
PopD
add a comment |
As your mask is a file and the @path will contain the file name,
you'll have to cd to the folder with .. appended to it @path..
So try:
forfiles /P C:Sales /S /M file1* /D -7 /C "cmd.exe /c @cd /D @path..&del file1 file3 file6 file8"
This command will also find file1 matching the criteria directly in C:Sales
A more consize solution using PowerShell
Get-ChildItem "C:SalesClient*file1" -File |
Where LastWriteTime -lt (Get-Date).Date.AddDays(-7)|
ForEach-Object
PushD $_.Directory
Remove-Object file[1368]
PopD
As your mask is a file and the @path will contain the file name,
you'll have to cd to the folder with .. appended to it @path..
So try:
forfiles /P C:Sales /S /M file1* /D -7 /C "cmd.exe /c @cd /D @path..&del file1 file3 file6 file8"
This command will also find file1 matching the criteria directly in C:Sales
A more consize solution using PowerShell
Get-ChildItem "C:SalesClient*file1" -File |
Where LastWriteTime -lt (Get-Date).Date.AddDays(-7)|
ForEach-Object
PushD $_.Directory
Remove-Object file[1368]
PopD
edited Mar 7 at 15:04
answered Mar 7 at 12:40
LotPingsLotPings
19.9k61633
19.9k61633
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%2f55042842%2fdelete-files-in-multiple-subfolders-with-batch%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
2
Stack Overflow isn't a script writing service, what have you tried so far? edit your question to conntain your efforts in a Minimal, Complete, and Verifiable example.
– LotPings
Mar 7 at 12:09
Yes, if you noticed i said that every solution i tried worked only for a given path, my problem is changing subfolder without having to add a line for every folder.
– dammyware
Mar 7 at 13:52
1
This site expects you to provide the code you've tried which is causing the issue you're reporting. If you've tried more than one solution, it is important that you post those attempts and explain exactly what happens, which differs from yuor expectaitions, when you run each.
– Compo
Mar 7 at 14:06