Been beating my head on this one for awhile<\/p>\n
I am basically trying to list each folder and sub folder ( which works fine) than for each folder i want to check if a file exist in that folder(this part doesnt work) and if it does check if another file exist…<\/p>\n
The below is just listing each folder than checking if a txt file exists in that folder<\/p>\n
using Get-ChildItem -Path $_ -Include .bmp,<\/em>.txt -File -Recurse just errors out for some reason…<\/p>\n would love any help on solving the problem…or if someone wants to take it one step further and finish the last step after this which is checking if a tif file exist in the folder and if it does checking if an xml file exists too i would be grateful too<\/p>\n if you just select the folder (-directory) , you’d have to query each folder again for it’s content, as using ‘-directory’ only returns the top level folder.<\/p>\n I think what you want is this:<\/p>\n Been beating my head on this one for awhile<\/p>\n I am basically trying to list each folder and sub folder ( which works fine) than for each folder i want to check if a file exist in that folder(this part doesnt work) and if it does check if another file exist…<\/p>\n The below is just listing each folder than checking if a txt file exists in that folder<\/p>\n using Get-ChildItem -Path $_ -Include .bmp,<\/em>.txt -File -Recurse just errors out for some reason…<\/p>\n would love any help on solving the problem…or if someone wants to take it one step further and finish the last step after this which is checking if a tif file exist in the folder and if it does checking if an xml file exists too i would be grateful too<\/p>\n Welcome<\/p>\n If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>\n$folders=Get-ChildItem -Path C:\\Users\\test\\Downloads\\scripttest\\ -Recurse -Directory -Force -ErrorAction SilentlyContinue | Select-Object FullName\n\n$folders|foreach{\n\nWrite-Output $_\n\nusing Test-Path -Path $_*.txt -PathType Leaf\n\n}\n\n<\/code><\/pre>","upvoteCount":3,"answerCount":13,"datePublished":"2021-08-23T04:17:10.000Z","author":{"@type":"Person","name":"spiceuser-etvsa","url":"https://community.spiceworks.com/u/spiceuser-etvsa"},"acceptedAnswer":{"@type":"Answer","text":"
$Folders = Get-childitem \"D:\\test2\" -Recurse -Directory\n\nforeach($Folder in $Folders){\n write-verbose \"Folder: $($folder.fullname)\" -verbose\n if(Test-Path \"$($Folder.fullname)\\*.txt\"){\n write-output \"Folder $($folder.name) contains TXT files.\"\n }\n}\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2021-08-23T05:24:54.000Z","url":"https://community.spiceworks.com/t/going-through-folders/809114/12","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},"suggestedAnswer":[{"@type":"Answer","text":"
$folders=Get-ChildItem -Path C:\\Users\\test\\Downloads\\scripttest\\ -Recurse -Directory -Force -ErrorAction SilentlyContinue | Select-Object FullName\n\n$folders|foreach{\n\nWrite-Output $_\n\nusing Test-Path -Path $_*.txt -PathType Leaf\n\n}\n\n<\/code><\/pre>","upvoteCount":3,"datePublished":"2021-08-23T04:17:10.000Z","url":"https://community.spiceworks.com/t/going-through-folders/809114/1","author":{"@type":"Person","name":"spiceuser-etvsa","url":"https://community.spiceworks.com/u/spiceuser-etvsa"}},{"@type":"Answer","text":"