?
Solved

Create a txt file in each folder of a folder structure

Posted on 2014-04-03
13
Medium Priority
?
273 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 35

Expert Comment

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

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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 35

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 35

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
 

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 35

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 35

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 35

Accepted Solution

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

Open in new window

0
 
LVL 35

Expert Comment

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

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Log files are useful in diagnosing and repairing problems.  This is a list of common log files and their standard locations that I've compiled.   While this is not exhaustive, it is a pretty good list that I've found to be useful.  I may update it f…
Ever notice how you can't use a new drive in Windows without having Windows assigning a Disk Signature?  Ever have a signature collision problem (especially with Virtual Machines?)  This article is intended to help you understand what's going on and…
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…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

770 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