sirichaiphumirat
asked on
finding file in powershell
I'm pretty new to powershell,
How would i use powershell to find a file and get the path. And also is it possible to use the path in a variable?
for example. I want to search for a file on my computer called mytestfile.exe
and get the path of its location. And put that location into a variable.
I was trying to use get-childitme -recurse -include, but i'm not sure if i am using it correctly
I seem to be able to get the directory but how would i put the path into a variable
thanks
How would i use powershell to find a file and get the path. And also is it possible to use the path in a variable?
for example. I want to search for a file on my computer called mytestfile.exe
and get the path of its location. And put that location into a variable.
I was trying to use get-childitme -recurse -include, but i'm not sure if i am using it correctly
I seem to be able to get the directory but how would i put the path into a variable
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
that depends on what you intend to do with your results:
This will deplay the results on the screen:
$files = get-childitem c:\ -recurse | ? {$_.name -eq "mytestfile.exe"}
write-host there are $files.count matching that name
foreach ($file in $files){
$directory = $file.directory
$fulldirectorypath = $file.directory.fullname
$fullfilepath = $file.fullname
write-host $file.name
write-host the directory path is $fulldirectorypath
}
This will deplay the results on the screen:
$files = get-childitem c:\ -recurse | ? {$_.name -eq "mytestfile.exe"}
write-host there are $files.count matching that name
foreach ($file in $files){
$directory = $file.directory
$fulldirectorypath = $file.directory.fullname
$fullfilepath = $file.fullname
write-host $file.name
write-host the directory path is $fulldirectorypath
}
ASKER
Thank you, you been very help full.
you are welcome
ASKER