E
E
etozhesano2020-08-05 10:18:37
PowerShell
etozhesano, 2020-08-05 10:18:37

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

1 answer(s)
A
azarij, 2020-08-05
@etozhesano

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 question

Ask a Question

731 491 924 answers to any question