![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Write files in directory tree For a project I'd like to do the following: - Run a script from the top to the bottom of a directory tree - In each folder of that tree a textfile must be created - The name of the textfile has to be the current path of the folder This way I would end up with a directory tree where each folder has a textfile in it named after the location of the folder. At this moment I started learning Powershell, and I think this could easily be done. I started trying with the new-item command in combination with recurse but it didn't work out. Anyone any idea how to script this in powershell ? TIA |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Write files in directory tree You cant write text file with path charecters in it. Some charecters are not allowed as file names, you need to find another naming scheme for the text files. As for the recurse operation, that can easily be done. dir <path> -recurse | where {$_.psiscontainer} | foreach {new-item -type file -path $_.fullname -name "yourname.txt"} Shay http://scriptolog.blogspot.com > For a project I'd like to do the following: > > - Run a script from the top to the bottom of a directory tree > - In each folder of that tree a textfile must be created > - The name of the textfile has to be the current path of the folder > This way I would end up with a directory tree where each folder has a > textfile in it named after the location of the folder. > > At this moment I started learning Powershell, and I think this could > easily be done. I started trying with the new-item command in > combination with recurse but it didn't work out. > > Anyone any idea how to script this in powershell ? TIA > |
My System Specs![]() |
| | #3 (permalink) |
| | RE: Write files in directory tree Oneliner: ls -rec -force | ?{$_.psiscontainer} | %{$_.fullname > "$($_.fullname)\path.txt"} -- greetings dreeschkind "ArjanS" wrote: > For a project I'd like to do the following: > > - Run a script from the top to the bottom of a directory tree > - In each folder of that tree a textfile must be created > - The name of the textfile has to be the current path of the folder > > This way I would end up with a directory tree where each folder has a > textfile in it named after the location of the folder. > > At this moment I started learning Powershell, and I think this could easily > be done. I started trying with the new-item command in combination with > recurse but it didn't work out. > > Anyone any idea how to script this in powershell ? TIA > > |
My System Specs![]() |
| | #4 (permalink) |
| | RE: Write files in directory tree Ah, missed the fact that you wanted the path as the name of the file. Try this instead: ls -rec -force | ? {$_.psiscontainer} | % {ni -path "$($_.fullname)\$($_.fullname -replace '\\','-' -replace ':','+')" -type file} It replaces the backshlashes and the colon so the filename is valid. -- greetings dreeschkind "ArjanS" wrote: > For a project I'd like to do the following: > > - Run a script from the top to the bottom of a directory tree > - In each folder of that tree a textfile must be created > - The name of the textfile has to be the current path of the folder > > This way I would end up with a directory tree where each folder has a > textfile in it named after the location of the folder. > > At this moment I started learning Powershell, and I think this could easily > be done. I started trying with the new-item command in combination with > recurse but it didn't work out. > > Anyone any idea how to script this in powershell ? TIA > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Directory Tree Iterations | General Discussion | |||
| Vista Won't Let Me Create XP-Style Directory Tree for Old Template Files | Vista file management | |||
| Hard Drive Directory Tree | Vista file management | |||
| How to open a file for read/write access in Program Files directory | Vista security | |||
| Directory tree? | Vista installation & setup | |||