Solved

Create a txt file in each folder of a folder structure

Posted on 2014-04-03
13
264 Views
Last Modified: 2014-04-03
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
Comment
Question by:whenz
13 Comments
 
LVL 35

Expert Comment

by:Joseph Daly
ID: 39975225
Do these folders have subfolders?
0
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39975241
gci X:\your\path -Directory -Recurse | | %{New-Item "$($_.FullName)\test.txt" -ItemType file}

Open in new window


HTH,
Dan
0
 

Author Comment

by:whenz
ID: 39975247
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
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39975266
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
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39975276
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
 
LVL 13

Expert Comment

by:Santosh Gupta
ID: 39975285
hi,

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

forfiles /p d:\ /s /c "cmd /c echo  dd > @pathabc.txt"
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:whenz
ID: 39975294
I will run the script on a Windows 2008 R2 Server, so I guess I have powershell 3?
0
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39975321
Probably 2. You can find out by typing "host" at the powershell prompt.
0
 

Author Comment

by:whenz
ID: 39975326
Yup, Powershell 3

Name    : ConsoleHost
Version : 3.0
0
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39975339
Great! Someone there actually installed the update :)
Then the script for PS 3 should work and produce hundreds of empty text documents.
0
 

Author Comment

by:whenz
ID: 39975341
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
 
LVL 34

Accepted Solution

by:
Dan Craciun earned 500 total points
ID: 39975354
Like this:
gci X:\your\path -recurse -include "test.txt" | Remove-Item

Open in new window

0
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39975370
Glad I could help!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Preface Having the need * to contact many different companies with different infrastructures * do remote maintenance in their network required us to implement a more flexible routing solution. As RAS, PPTP, L2TP and VPN Client connections are no…
by Nathan Brom/Bromy2004 Introduction There are numerous websites out there for any different type of program you can imagine.  Of those, you'll need to decide which ones are legitimate and aren't trying to steal your money or infect your comput…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now