Accessing variables outside foreach inside it in powershell -


I have a simple code sample in which I wanted a loop through the directory contents:
 
Code> $ path = "c: \ user \ bissau \ desktop \ novel" $ content = dir-path $ path | Where are the items under {$ _ mode-match "^ D. *"} Foreach ($ item in $ content) {"Folder $ path \ $ item:" Dior-path "$ path \ $ item" | Name, mode}}

The problem is that the script is not able to read the variable $ path inside the fire-loop loop. Can someone give me some ideas? Is this normal behavior?

Your foreach command should be shown below, note that printing the line You do not have echo and you ;

  foreach ($ item $ in content) {"folder $ path \ $ items are itemized under:"; The "path" $ path \ $ item | Select the name, mode   

You can try that it's called Dior by using ForEach-Object commandlet

  -path $ path. Where {$ _ mode mode "^ D. *"} | There are items under the {Write-host "folder $ path \ $ _ for every object:"; Dir-path "$ path \ $ _" | Name, mode}    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -