Delete specific folders at UNC location
I'm trying to create a batch script to delete all folders having "Exception_" in it's name from the current folder in a remote desktop. I used this answer to a previous question to come up with the below script.
@echo off
setlocal enabledelayedexpansion
rem find directories called Exception_
for /f "usebackq tokens=*" %%i in (`dir /b /s /a:d Exception_`) do (
rem delete the directories and any files or subdirectories
rd /s /q "%%i"
)
endlocal
However, the command prompt is showing that UNC paths are not supported. Any way to make this work ?
batch script unc
add a comment |
I'm trying to create a batch script to delete all folders having "Exception_" in it's name from the current folder in a remote desktop. I used this answer to a previous question to come up with the below script.
@echo off
setlocal enabledelayedexpansion
rem find directories called Exception_
for /f "usebackq tokens=*" %%i in (`dir /b /s /a:d Exception_`) do (
rem delete the directories and any files or subdirectories
rd /s /q "%%i"
)
endlocal
However, the command prompt is showing that UNC paths are not supported. Any way to make this work ?
batch script unc
add a comment |
I'm trying to create a batch script to delete all folders having "Exception_" in it's name from the current folder in a remote desktop. I used this answer to a previous question to come up with the below script.
@echo off
setlocal enabledelayedexpansion
rem find directories called Exception_
for /f "usebackq tokens=*" %%i in (`dir /b /s /a:d Exception_`) do (
rem delete the directories and any files or subdirectories
rd /s /q "%%i"
)
endlocal
However, the command prompt is showing that UNC paths are not supported. Any way to make this work ?
batch script unc
I'm trying to create a batch script to delete all folders having "Exception_" in it's name from the current folder in a remote desktop. I used this answer to a previous question to come up with the below script.
@echo off
setlocal enabledelayedexpansion
rem find directories called Exception_
for /f "usebackq tokens=*" %%i in (`dir /b /s /a:d Exception_`) do (
rem delete the directories and any files or subdirectories
rd /s /q "%%i"
)
endlocal
However, the command prompt is showing that UNC paths are not supported. Any way to make this work ?
batch script unc
batch script unc
asked Feb 27 at 15:16
NewbieNewbie
12
12
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Use the pushd command:
Stores the current directory for use by the popd command, and then
changes to the specified directory.
Syntax
pushd [<Path>]
The command will create a temporary drive letter mapped to your UNC root
location and effectively CD to that location.
For example:
@echo off
pushd \servershare
for /f "usebackq tokens=*" ...
Thanks for your response. However, it does not seem to work. I replaced the setlocal command with pushd <path>. It did create a temporary network drive but always returns a "File Not Found" prompt even when there are folders with "Exception_" in their name. The folders do not get deleted
– Newbie
Feb 27 at 17:23
This is a problem with the script. It should usedir /b /s /a:d Exception_*.
– harrymc
Feb 27 at 17:34
Thanks for pointing that out. But the prompt shows "The system cannot find the file 'dir /b /s /a:d Exception_*". Am I doing something wrong here as I'm trying to delete a folder by that name and not a file? Also, where should I place the popd command exactly. I'm sorry if this is too basic but I'm kind of new to batch scripting
– Newbie
Feb 27 at 17:42
It works for me. Try to debug with simplified syntax such asfor /f %%i in ('dir /b /s /a:d Exception_*') do echo %%i.
– harrymc
Feb 27 at 17:57
add a comment |
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%2f1409898%2fdelete-specific-folders-at-unc-location%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
Use the pushd command:
Stores the current directory for use by the popd command, and then
changes to the specified directory.
Syntax
pushd [<Path>]
The command will create a temporary drive letter mapped to your UNC root
location and effectively CD to that location.
For example:
@echo off
pushd \servershare
for /f "usebackq tokens=*" ...
Thanks for your response. However, it does not seem to work. I replaced the setlocal command with pushd <path>. It did create a temporary network drive but always returns a "File Not Found" prompt even when there are folders with "Exception_" in their name. The folders do not get deleted
– Newbie
Feb 27 at 17:23
This is a problem with the script. It should usedir /b /s /a:d Exception_*.
– harrymc
Feb 27 at 17:34
Thanks for pointing that out. But the prompt shows "The system cannot find the file 'dir /b /s /a:d Exception_*". Am I doing something wrong here as I'm trying to delete a folder by that name and not a file? Also, where should I place the popd command exactly. I'm sorry if this is too basic but I'm kind of new to batch scripting
– Newbie
Feb 27 at 17:42
It works for me. Try to debug with simplified syntax such asfor /f %%i in ('dir /b /s /a:d Exception_*') do echo %%i.
– harrymc
Feb 27 at 17:57
add a comment |
Use the pushd command:
Stores the current directory for use by the popd command, and then
changes to the specified directory.
Syntax
pushd [<Path>]
The command will create a temporary drive letter mapped to your UNC root
location and effectively CD to that location.
For example:
@echo off
pushd \servershare
for /f "usebackq tokens=*" ...
Thanks for your response. However, it does not seem to work. I replaced the setlocal command with pushd <path>. It did create a temporary network drive but always returns a "File Not Found" prompt even when there are folders with "Exception_" in their name. The folders do not get deleted
– Newbie
Feb 27 at 17:23
This is a problem with the script. It should usedir /b /s /a:d Exception_*.
– harrymc
Feb 27 at 17:34
Thanks for pointing that out. But the prompt shows "The system cannot find the file 'dir /b /s /a:d Exception_*". Am I doing something wrong here as I'm trying to delete a folder by that name and not a file? Also, where should I place the popd command exactly. I'm sorry if this is too basic but I'm kind of new to batch scripting
– Newbie
Feb 27 at 17:42
It works for me. Try to debug with simplified syntax such asfor /f %%i in ('dir /b /s /a:d Exception_*') do echo %%i.
– harrymc
Feb 27 at 17:57
add a comment |
Use the pushd command:
Stores the current directory for use by the popd command, and then
changes to the specified directory.
Syntax
pushd [<Path>]
The command will create a temporary drive letter mapped to your UNC root
location and effectively CD to that location.
For example:
@echo off
pushd \servershare
for /f "usebackq tokens=*" ...
Use the pushd command:
Stores the current directory for use by the popd command, and then
changes to the specified directory.
Syntax
pushd [<Path>]
The command will create a temporary drive letter mapped to your UNC root
location and effectively CD to that location.
For example:
@echo off
pushd \servershare
for /f "usebackq tokens=*" ...
answered Feb 27 at 17:05
harrymcharrymc
264k14273581
264k14273581
Thanks for your response. However, it does not seem to work. I replaced the setlocal command with pushd <path>. It did create a temporary network drive but always returns a "File Not Found" prompt even when there are folders with "Exception_" in their name. The folders do not get deleted
– Newbie
Feb 27 at 17:23
This is a problem with the script. It should usedir /b /s /a:d Exception_*.
– harrymc
Feb 27 at 17:34
Thanks for pointing that out. But the prompt shows "The system cannot find the file 'dir /b /s /a:d Exception_*". Am I doing something wrong here as I'm trying to delete a folder by that name and not a file? Also, where should I place the popd command exactly. I'm sorry if this is too basic but I'm kind of new to batch scripting
– Newbie
Feb 27 at 17:42
It works for me. Try to debug with simplified syntax such asfor /f %%i in ('dir /b /s /a:d Exception_*') do echo %%i.
– harrymc
Feb 27 at 17:57
add a comment |
Thanks for your response. However, it does not seem to work. I replaced the setlocal command with pushd <path>. It did create a temporary network drive but always returns a "File Not Found" prompt even when there are folders with "Exception_" in their name. The folders do not get deleted
– Newbie
Feb 27 at 17:23
This is a problem with the script. It should usedir /b /s /a:d Exception_*.
– harrymc
Feb 27 at 17:34
Thanks for pointing that out. But the prompt shows "The system cannot find the file 'dir /b /s /a:d Exception_*". Am I doing something wrong here as I'm trying to delete a folder by that name and not a file? Also, where should I place the popd command exactly. I'm sorry if this is too basic but I'm kind of new to batch scripting
– Newbie
Feb 27 at 17:42
It works for me. Try to debug with simplified syntax such asfor /f %%i in ('dir /b /s /a:d Exception_*') do echo %%i.
– harrymc
Feb 27 at 17:57
Thanks for your response. However, it does not seem to work. I replaced the setlocal command with pushd <path>. It did create a temporary network drive but always returns a "File Not Found" prompt even when there are folders with "Exception_" in their name. The folders do not get deleted
– Newbie
Feb 27 at 17:23
Thanks for your response. However, it does not seem to work. I replaced the setlocal command with pushd <path>. It did create a temporary network drive but always returns a "File Not Found" prompt even when there are folders with "Exception_" in their name. The folders do not get deleted
– Newbie
Feb 27 at 17:23
This is a problem with the script. It should use
dir /b /s /a:d Exception_*.– harrymc
Feb 27 at 17:34
This is a problem with the script. It should use
dir /b /s /a:d Exception_*.– harrymc
Feb 27 at 17:34
Thanks for pointing that out. But the prompt shows "The system cannot find the file '
dir /b /s /a:d Exception_*". Am I doing something wrong here as I'm trying to delete a folder by that name and not a file? Also, where should I place the popd command exactly. I'm sorry if this is too basic but I'm kind of new to batch scripting– Newbie
Feb 27 at 17:42
Thanks for pointing that out. But the prompt shows "The system cannot find the file '
dir /b /s /a:d Exception_*". Am I doing something wrong here as I'm trying to delete a folder by that name and not a file? Also, where should I place the popd command exactly. I'm sorry if this is too basic but I'm kind of new to batch scripting– Newbie
Feb 27 at 17:42
It works for me. Try to debug with simplified syntax such as
for /f %%i in ('dir /b /s /a:d Exception_*') do echo %%i.– harrymc
Feb 27 at 17:57
It works for me. Try to debug with simplified syntax such as
for /f %%i in ('dir /b /s /a:d Exception_*') do echo %%i.– harrymc
Feb 27 at 17:57
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%2f1409898%2fdelete-specific-folders-at-unc-location%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
