Getting single Subfolder name but not its contents
This seem so simple but I can not seem to find the answer. I have a root folder called Processing. Inside the root folder, a user will move a folder with hundreds of other folders and files. I do not know what the name of that folder will be called.
All I'm trying to do is get that single subfolders name and put it in a variable.
Thank you in advance!
**Such as:**
$folderName = SUBFOLDER
PROCESSING
-> SUBFOLDER (All I need is this name)
->F1 (Not any of these)
->F2
->F3
->etc...
windows-10 powershell environment-variables
add a comment |
This seem so simple but I can not seem to find the answer. I have a root folder called Processing. Inside the root folder, a user will move a folder with hundreds of other folders and files. I do not know what the name of that folder will be called.
All I'm trying to do is get that single subfolders name and put it in a variable.
Thank you in advance!
**Such as:**
$folderName = SUBFOLDER
PROCESSING
-> SUBFOLDER (All I need is this name)
->F1 (Not any of these)
->F2
->F3
->etc...
windows-10 powershell environment-variables
add a comment |
This seem so simple but I can not seem to find the answer. I have a root folder called Processing. Inside the root folder, a user will move a folder with hundreds of other folders and files. I do not know what the name of that folder will be called.
All I'm trying to do is get that single subfolders name and put it in a variable.
Thank you in advance!
**Such as:**
$folderName = SUBFOLDER
PROCESSING
-> SUBFOLDER (All I need is this name)
->F1 (Not any of these)
->F2
->F3
->etc...
windows-10 powershell environment-variables
This seem so simple but I can not seem to find the answer. I have a root folder called Processing. Inside the root folder, a user will move a folder with hundreds of other folders and files. I do not know what the name of that folder will be called.
All I'm trying to do is get that single subfolders name and put it in a variable.
Thank you in advance!
**Such as:**
$folderName = SUBFOLDER
PROCESSING
-> SUBFOLDER (All I need is this name)
->F1 (Not any of these)
->F2
->F3
->etc...
windows-10 powershell environment-variables
windows-10 powershell environment-variables
asked Jan 8 at 23:41
Tohny.JohnsonTohny.Johnson
737
737
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
To exclude the F1, F2, etc., don't use the -Recurse option. Also, use -Name to get just the name of the subfolder without any of the additional data. So,
$foldername = get-childitem -Path C:TempProcessing -Directory -Name
will put the name of that subfolder (you said there was only one) in the $foldername variable.
This worked PERFECT, thank you very much!
– Tohny.Johnson
Jan 9 at 0:13
Though the OP did not state, it, I chose to use recurse make the assumption that that OP could be starting high in the tree. My temp folder has dozens of folder and subfolders in it. That NewFiles folder in not below temp, it's deeper, hence the recurse. to find the folder no matter where is was in the tree.
– postanote
Jan 9 at 0:16
add a comment |
You'd use the -filter and -Directory switch.
$folder = 'NewFiles'
Get-ChildItem -Path 'D:Temp' -Filter $folder -Directory -Recurse
Directory: D:Temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 30-Dec-18 20:39 NewFiles
Update for the OP.
Correct, NewFiles is a grand child of temp.
(Get-ChildItem -Path 'D:Temp' -Filter $folder -Directory -Recurse).FullName
# actual UNC
D:TempPngFilesNewFiles
Thank you for the reply. When I try to use the above code, all I get is the name "NewFiles" it doesn't pull the name of the folder in the root folder. If I'm understanding correctly in your code the path D:Temp is scanned pulling the subfolder name "NewFiles" correct? That is what I'm trying to acheve but it seems like "NewFiles" is just set and the Get-ChildItem isn't doing anything.
– Tohny.Johnson
Jan 9 at 0:11
Correct, NewFiles is a grand child of temp.
– postanote
Jan 9 at 0:16
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%2f1392074%2fgetting-single-subfolder-name-but-not-its-contents%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
To exclude the F1, F2, etc., don't use the -Recurse option. Also, use -Name to get just the name of the subfolder without any of the additional data. So,
$foldername = get-childitem -Path C:TempProcessing -Directory -Name
will put the name of that subfolder (you said there was only one) in the $foldername variable.
This worked PERFECT, thank you very much!
– Tohny.Johnson
Jan 9 at 0:13
Though the OP did not state, it, I chose to use recurse make the assumption that that OP could be starting high in the tree. My temp folder has dozens of folder and subfolders in it. That NewFiles folder in not below temp, it's deeper, hence the recurse. to find the folder no matter where is was in the tree.
– postanote
Jan 9 at 0:16
add a comment |
To exclude the F1, F2, etc., don't use the -Recurse option. Also, use -Name to get just the name of the subfolder without any of the additional data. So,
$foldername = get-childitem -Path C:TempProcessing -Directory -Name
will put the name of that subfolder (you said there was only one) in the $foldername variable.
This worked PERFECT, thank you very much!
– Tohny.Johnson
Jan 9 at 0:13
Though the OP did not state, it, I chose to use recurse make the assumption that that OP could be starting high in the tree. My temp folder has dozens of folder and subfolders in it. That NewFiles folder in not below temp, it's deeper, hence the recurse. to find the folder no matter where is was in the tree.
– postanote
Jan 9 at 0:16
add a comment |
To exclude the F1, F2, etc., don't use the -Recurse option. Also, use -Name to get just the name of the subfolder without any of the additional data. So,
$foldername = get-childitem -Path C:TempProcessing -Directory -Name
will put the name of that subfolder (you said there was only one) in the $foldername variable.
To exclude the F1, F2, etc., don't use the -Recurse option. Also, use -Name to get just the name of the subfolder without any of the additional data. So,
$foldername = get-childitem -Path C:TempProcessing -Directory -Name
will put the name of that subfolder (you said there was only one) in the $foldername variable.
answered Jan 9 at 0:04
Doug DedenDoug Deden
44816
44816
This worked PERFECT, thank you very much!
– Tohny.Johnson
Jan 9 at 0:13
Though the OP did not state, it, I chose to use recurse make the assumption that that OP could be starting high in the tree. My temp folder has dozens of folder and subfolders in it. That NewFiles folder in not below temp, it's deeper, hence the recurse. to find the folder no matter where is was in the tree.
– postanote
Jan 9 at 0:16
add a comment |
This worked PERFECT, thank you very much!
– Tohny.Johnson
Jan 9 at 0:13
Though the OP did not state, it, I chose to use recurse make the assumption that that OP could be starting high in the tree. My temp folder has dozens of folder and subfolders in it. That NewFiles folder in not below temp, it's deeper, hence the recurse. to find the folder no matter where is was in the tree.
– postanote
Jan 9 at 0:16
This worked PERFECT, thank you very much!
– Tohny.Johnson
Jan 9 at 0:13
This worked PERFECT, thank you very much!
– Tohny.Johnson
Jan 9 at 0:13
Though the OP did not state, it, I chose to use recurse make the assumption that that OP could be starting high in the tree. My temp folder has dozens of folder and subfolders in it. That NewFiles folder in not below temp, it's deeper, hence the recurse. to find the folder no matter where is was in the tree.
– postanote
Jan 9 at 0:16
Though the OP did not state, it, I chose to use recurse make the assumption that that OP could be starting high in the tree. My temp folder has dozens of folder and subfolders in it. That NewFiles folder in not below temp, it's deeper, hence the recurse. to find the folder no matter where is was in the tree.
– postanote
Jan 9 at 0:16
add a comment |
You'd use the -filter and -Directory switch.
$folder = 'NewFiles'
Get-ChildItem -Path 'D:Temp' -Filter $folder -Directory -Recurse
Directory: D:Temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 30-Dec-18 20:39 NewFiles
Update for the OP.
Correct, NewFiles is a grand child of temp.
(Get-ChildItem -Path 'D:Temp' -Filter $folder -Directory -Recurse).FullName
# actual UNC
D:TempPngFilesNewFiles
Thank you for the reply. When I try to use the above code, all I get is the name "NewFiles" it doesn't pull the name of the folder in the root folder. If I'm understanding correctly in your code the path D:Temp is scanned pulling the subfolder name "NewFiles" correct? That is what I'm trying to acheve but it seems like "NewFiles" is just set and the Get-ChildItem isn't doing anything.
– Tohny.Johnson
Jan 9 at 0:11
Correct, NewFiles is a grand child of temp.
– postanote
Jan 9 at 0:16
add a comment |
You'd use the -filter and -Directory switch.
$folder = 'NewFiles'
Get-ChildItem -Path 'D:Temp' -Filter $folder -Directory -Recurse
Directory: D:Temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 30-Dec-18 20:39 NewFiles
Update for the OP.
Correct, NewFiles is a grand child of temp.
(Get-ChildItem -Path 'D:Temp' -Filter $folder -Directory -Recurse).FullName
# actual UNC
D:TempPngFilesNewFiles
Thank you for the reply. When I try to use the above code, all I get is the name "NewFiles" it doesn't pull the name of the folder in the root folder. If I'm understanding correctly in your code the path D:Temp is scanned pulling the subfolder name "NewFiles" correct? That is what I'm trying to acheve but it seems like "NewFiles" is just set and the Get-ChildItem isn't doing anything.
– Tohny.Johnson
Jan 9 at 0:11
Correct, NewFiles is a grand child of temp.
– postanote
Jan 9 at 0:16
add a comment |
You'd use the -filter and -Directory switch.
$folder = 'NewFiles'
Get-ChildItem -Path 'D:Temp' -Filter $folder -Directory -Recurse
Directory: D:Temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 30-Dec-18 20:39 NewFiles
Update for the OP.
Correct, NewFiles is a grand child of temp.
(Get-ChildItem -Path 'D:Temp' -Filter $folder -Directory -Recurse).FullName
# actual UNC
D:TempPngFilesNewFiles
You'd use the -filter and -Directory switch.
$folder = 'NewFiles'
Get-ChildItem -Path 'D:Temp' -Filter $folder -Directory -Recurse
Directory: D:Temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 30-Dec-18 20:39 NewFiles
Update for the OP.
Correct, NewFiles is a grand child of temp.
(Get-ChildItem -Path 'D:Temp' -Filter $folder -Directory -Recurse).FullName
# actual UNC
D:TempPngFilesNewFiles
edited Jan 9 at 0:18
answered Jan 8 at 23:57
postanotepostanote
97833
97833
Thank you for the reply. When I try to use the above code, all I get is the name "NewFiles" it doesn't pull the name of the folder in the root folder. If I'm understanding correctly in your code the path D:Temp is scanned pulling the subfolder name "NewFiles" correct? That is what I'm trying to acheve but it seems like "NewFiles" is just set and the Get-ChildItem isn't doing anything.
– Tohny.Johnson
Jan 9 at 0:11
Correct, NewFiles is a grand child of temp.
– postanote
Jan 9 at 0:16
add a comment |
Thank you for the reply. When I try to use the above code, all I get is the name "NewFiles" it doesn't pull the name of the folder in the root folder. If I'm understanding correctly in your code the path D:Temp is scanned pulling the subfolder name "NewFiles" correct? That is what I'm trying to acheve but it seems like "NewFiles" is just set and the Get-ChildItem isn't doing anything.
– Tohny.Johnson
Jan 9 at 0:11
Correct, NewFiles is a grand child of temp.
– postanote
Jan 9 at 0:16
Thank you for the reply. When I try to use the above code, all I get is the name "NewFiles" it doesn't pull the name of the folder in the root folder. If I'm understanding correctly in your code the path D:Temp is scanned pulling the subfolder name "NewFiles" correct? That is what I'm trying to acheve but it seems like "NewFiles" is just set and the Get-ChildItem isn't doing anything.
– Tohny.Johnson
Jan 9 at 0:11
Thank you for the reply. When I try to use the above code, all I get is the name "NewFiles" it doesn't pull the name of the folder in the root folder. If I'm understanding correctly in your code the path D:Temp is scanned pulling the subfolder name "NewFiles" correct? That is what I'm trying to acheve but it seems like "NewFiles" is just set and the Get-ChildItem isn't doing anything.
– Tohny.Johnson
Jan 9 at 0:11
Correct, NewFiles is a grand child of temp.
– postanote
Jan 9 at 0:16
Correct, NewFiles is a grand child of temp.
– postanote
Jan 9 at 0:16
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%2f1392074%2fgetting-single-subfolder-name-but-not-its-contents%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