How to Create empty text file in every subfolder of a directory at once?

User077 21 Reputation points
2022-12-31T11:56:35.91+00:00

Let's say there is a folder "New Folder" its path is <"E:\Folders\New folder">
Now there are Sub folders "A" , "B" , "C" , "D" , "E" inside "New Folder". Now What i want is to create a .txt file (Any name) in all the sub folders (ie; inside A B C D E).
I would like to do it with PowerShell but would also don't mind using some software.

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 36,291 Reputation points
    2022-12-31T14:10:15.723+00:00

    Remove the -Whatif to actually create the file.

    Get-ChildItem -Path "E:\Folders\New folder" -Directory -Recurse | ForEach-Object {New-Item -Path $_.FullName -Name "testfile1.txt" -ItemType File -WhatIf }  
    
    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.