Delete multiple files on PowerShell command line
With PowerShell, what is the most concise way to delete multiple explicitly named files?
E.g. on *ix it would be:
rm subDir/a.png anotherDir/b.jpg thirdDir/c.gif
I'm currently using:
echo subDir/a.png anotherDir/b.jpg thirdDir/c.gif|rm
But I consider it suboptimal, so I would like to see alternatives.
powershell file-management
add a comment |
With PowerShell, what is the most concise way to delete multiple explicitly named files?
E.g. on *ix it would be:
rm subDir/a.png anotherDir/b.jpg thirdDir/c.gif
I'm currently using:
echo subDir/a.png anotherDir/b.jpg thirdDir/c.gif|rm
But I consider it suboptimal, so I would like to see alternatives.
powershell file-management
add a comment |
With PowerShell, what is the most concise way to delete multiple explicitly named files?
E.g. on *ix it would be:
rm subDir/a.png anotherDir/b.jpg thirdDir/c.gif
I'm currently using:
echo subDir/a.png anotherDir/b.jpg thirdDir/c.gif|rm
But I consider it suboptimal, so I would like to see alternatives.
powershell file-management
With PowerShell, what is the most concise way to delete multiple explicitly named files?
E.g. on *ix it would be:
rm subDir/a.png anotherDir/b.jpg thirdDir/c.gif
I'm currently using:
echo subDir/a.png anotherDir/b.jpg thirdDir/c.gif|rm
But I consider it suboptimal, so I would like to see alternatives.
powershell file-management
powershell file-management
edited May 8 '17 at 14:43
djsmiley2k
5,11612336
5,11612336
asked Dec 16 '11 at 23:57
Matthew FlaschenMatthew Flaschen
2,18411426
2,18411426
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
You can give PowerShell's rm cmdlet (which is itself an alias for Remove-Item) several files, but you need to separate them with commas.
rm .subDira.png, .anotherDirb.jpg, .thirdDirc.gif
Check out Get-Help Remove-Item for more details. Or read some documentation on Microsoft's website.
add a comment |
This is what I ended up using:
echo subDir/a.png anotherDir/b.jpg thirdDir/c.gif|rm
This uses echo to pass three string arguments to rm (Remove-Item). I believe this implicitly uses Remove-Item's -Path parameter. The documentation notes that "The parameter name ("-Path") is optional" and it accepts pipeline input by value.
add a comment |
Old dog's trick, define an array first.
Put your stuff in it, and RM the heck out of it.
$myArray = @("subDir/a.png","subDir/b.png","thirdDir/c.gif")
rm $myArray
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
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%2fsuperuser.com%2fquestions%2f368830%2fdelete-multiple-files-on-powershell-command-line%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can give PowerShell's rm cmdlet (which is itself an alias for Remove-Item) several files, but you need to separate them with commas.
rm .subDira.png, .anotherDirb.jpg, .thirdDirc.gif
Check out Get-Help Remove-Item for more details. Or read some documentation on Microsoft's website.
add a comment |
You can give PowerShell's rm cmdlet (which is itself an alias for Remove-Item) several files, but you need to separate them with commas.
rm .subDira.png, .anotherDirb.jpg, .thirdDirc.gif
Check out Get-Help Remove-Item for more details. Or read some documentation on Microsoft's website.
add a comment |
You can give PowerShell's rm cmdlet (which is itself an alias for Remove-Item) several files, but you need to separate them with commas.
rm .subDira.png, .anotherDirb.jpg, .thirdDirc.gif
Check out Get-Help Remove-Item for more details. Or read some documentation on Microsoft's website.
You can give PowerShell's rm cmdlet (which is itself an alias for Remove-Item) several files, but you need to separate them with commas.
rm .subDira.png, .anotherDirb.jpg, .thirdDirc.gif
Check out Get-Help Remove-Item for more details. Or read some documentation on Microsoft's website.
edited Jan 15 at 18:31
answered Dec 17 '11 at 0:40
William JacksonWilliam Jackson
7,29312843
7,29312843
add a comment |
add a comment |
This is what I ended up using:
echo subDir/a.png anotherDir/b.jpg thirdDir/c.gif|rm
This uses echo to pass three string arguments to rm (Remove-Item). I believe this implicitly uses Remove-Item's -Path parameter. The documentation notes that "The parameter name ("-Path") is optional" and it accepts pipeline input by value.
add a comment |
This is what I ended up using:
echo subDir/a.png anotherDir/b.jpg thirdDir/c.gif|rm
This uses echo to pass three string arguments to rm (Remove-Item). I believe this implicitly uses Remove-Item's -Path parameter. The documentation notes that "The parameter name ("-Path") is optional" and it accepts pipeline input by value.
add a comment |
This is what I ended up using:
echo subDir/a.png anotherDir/b.jpg thirdDir/c.gif|rm
This uses echo to pass three string arguments to rm (Remove-Item). I believe this implicitly uses Remove-Item's -Path parameter. The documentation notes that "The parameter name ("-Path") is optional" and it accepts pipeline input by value.
This is what I ended up using:
echo subDir/a.png anotherDir/b.jpg thirdDir/c.gif|rm
This uses echo to pass three string arguments to rm (Remove-Item). I believe this implicitly uses Remove-Item's -Path parameter. The documentation notes that "The parameter name ("-Path") is optional" and it accepts pipeline input by value.
edited Dec 21 '11 at 12:39
Sathyajith Bhat♦
52.9k29156252
52.9k29156252
answered Dec 16 '11 at 23:57
Matthew FlaschenMatthew Flaschen
2,18411426
2,18411426
add a comment |
add a comment |
Old dog's trick, define an array first.
Put your stuff in it, and RM the heck out of it.
$myArray = @("subDir/a.png","subDir/b.png","thirdDir/c.gif")
rm $myArray
add a comment |
Old dog's trick, define an array first.
Put your stuff in it, and RM the heck out of it.
$myArray = @("subDir/a.png","subDir/b.png","thirdDir/c.gif")
rm $myArray
add a comment |
Old dog's trick, define an array first.
Put your stuff in it, and RM the heck out of it.
$myArray = @("subDir/a.png","subDir/b.png","thirdDir/c.gif")
rm $myArray
Old dog's trick, define an array first.
Put your stuff in it, and RM the heck out of it.
$myArray = @("subDir/a.png","subDir/b.png","thirdDir/c.gif")
rm $myArray
answered Nov 25 '17 at 17:31
JP LizotteJP Lizotte
1
1
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- 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%2fsuperuser.com%2fquestions%2f368830%2fdelete-multiple-files-on-powershell-command-line%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