• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:

Create a txt file in each folder of a folder structure

I have a folder structure with a couple of 100 folders.  The folders are currently empty.  As I have an issue with ABE (access based enumeration), I need to create a .txt file in each of these folders to test ABE.  it does not matter what the .txt file contains,

Can you please provide me a batch / powershell script which creates a .txt file in each folder?  Thank you!
0
whenz
Asked:
whenz
1 Solution
 
Joseph DalyCommented:
Do these folders have subfolders?
0
 
Dan CraciunIT ConsultantCommented:
gci X:\your\path -Directory -Recurse | | %{New-Item "$($_.FullName)\test.txt" -ItemType file}

Open in new window


HTH,
Dan
0
 
whenzAuthor Commented:
The process should be like this:

1. create a .txt file in each folder/subfolder.
2. I will run my tool which checks some permissions.
3. delete all .txt files in each folder/subfolder.

thx
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Dan CraciunIT ConsultantCommented:
For 1 you already have the solution.

BTW, what version of PS do you have? The one liner I posted works with PS 3 or above. Let me know if you need something for PS 2
0
 
Dan CraciunIT ConsultantCommented:
PS 3:
gci X:\your\path -Directory -Recurse | %{New-Item "$($_.FullName)\test.txt" -ItemType file}

Open in new window

PS 2:
gci X:\your\path -Recurse | ?{$_.PSIsContainer -eq $True} | %{New-Item "$($_.FullName)\test.txt" -ItemType file}

Open in new window

0
 
Santosh GuptaCommented:
hi,

Try this just change the path (d:\) with actual path

forfiles /p d:\ /s /c "cmd /c echo  dd > @pathabc.txt"
0
 
whenzAuthor Commented:
I will run the script on a Windows 2008 R2 Server, so I guess I have powershell 3?
0
 
Dan CraciunIT ConsultantCommented:
Probably 2. You can find out by typing "host" at the powershell prompt.
0
 
whenzAuthor Commented:
Yup, Powershell 3

Name    : ConsoleHost
Version : 3.0
0
 
Dan CraciunIT ConsultantCommented:
Great! Someone there actually installed the update :)
Then the script for PS 3 should work and produce hundreds of empty text documents.
0
 
whenzAuthor Commented:
Thanks Dan.  How should I delete the .txt files once I finished doing my stuff?  Should I search for the test.txt file and delete them?
0
 
Dan CraciunIT ConsultantCommented:
Like this:
gci X:\your\path -recurse -include "test.txt" | Remove-Item

Open in new window

0
 
Dan CraciunIT ConsultantCommented:
Glad I could help!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now