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!
whenzAsked:
Who is Participating?
 
Dan CraciunConnect With a Mentor IT ConsultantCommented:
Like this:
gci X:\your\path -recurse -include "test.txt" | Remove-Item

Open in new window

0
 
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
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
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
 
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:
Glad I could help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.