Solved

Create a txt file in each folder of a folder structure

Posted on 2014-04-03
13
269 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 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
Industry Leaders: 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!

 
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 500 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

Technology Partners: 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

Suggested Solutions

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…
When you upgrade from Windows 8 to 8.1 or to Windows 10 or if you are like me you are on the Insider Program you may find yourself with many 450MB recovery partitions.  With a traditional disk that may not be a problem but with relatively smaller SS…
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…

685 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