Answer the question
In order to leave comments, you need to log in
How to force powershell to search files in a folder but not child folders?
Hello. There is such a script element:
$filename = (Get-ChildItem D:\Example | sort lastwritetime | select -Last 1).fullname
Its essence is that it looks for the last file by date in the Example folder. But I also have other folders in the Example folder, for example (D:\Example\Random), in addition to the file. How can I make the script not search for child folders? Only in the Example folder
Answer the question
In order to leave comments, you need to log in
you do not have the -recurse key in the command, which means that it does not search in subfolders. Another question is that she sees the subfolders themselves.
try this:
$filename = (Get-ChildItem D:\Example -file | sort lastwritetime | select -Last 1).fullname
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question