Solved

Create a txt file in each folder of a folder structure

Posted on 2014-04-03
13
268 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
LPT Port to USB Printer Windows 7 23 733
SCCM 2012 14 34
What is hoipcy.exe 11 41
Windows Server 2012 Data Center Edition 11 118
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…
INTRODUCTION The purpose of this document is to demonstrate the Installation and configuration of the Data Protection Manager product. Note that this demonstration was prepared on the basis of Windows OS is 2008 R2 and DPM 2010. DATA PROTECTI…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
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). …

789 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