Solved

Create a txt file in each folder of a folder structure

Posted on 2014-04-03
13
267 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

This article describes how to set permissions to allow a limited-permissions user to start and stop a particular System Service.   It is always best to give users only the permissions that they need to perform their job, so tweaking particular permi…
The password reset disk is often mentioned as the best solution to deal with the lost Windows password problem. In Windows 2008, 7, Vista and XP, a password reset disk can be easily created. But besides Windows 7/Vista/XP, Windows Server 2008 and ot…
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). …
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…

776 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