Powershell loop through folders, create file in each folder

后端 未结 1 1480
无人共我
无人共我 2021-01-04 02:01

I\'m trying to recursively loop through all the folders in a directory, then do something within each directory. Create a text file, for example.

I can get all the s

相关标签:
1条回答
  • 2021-01-04 02:26

    Try this:

    Get-ChildItem -Recurse -Directory | ForEach-Object {New-Item -ItemType file -Path "$($_.FullName)" -Name "$($_.Name).txt" }
    

    Basically, the Get-ChildItem command returns a sequence of DirectoryInfo objects. The FullName property contains the full path, whilst Name just contains the name of the leaf directory.

    0 讨论(0)
提交回复
热议问题