How can I quickly create multiple titled text files in a folder?

I'm taking an online course that is organized in a very long list of sections. Each section contains often also a very long list of lectures. I have been copying each section title as a folder name from the File Explorer, but then continuing from there the creation of the long list of lecture note text files becomes cumbersome.

I'd like to easily give one command, for example from the command prompt, PowerShell, or a bash prompt, or something, to create all the titled lecture note files. Within the course content I can copy all the lecture titles and paste them into one text file that I can title, say lectures.txt. So, I have a lectures.txt file with, for the current section contains 24 numbered titles (226. example One through 249. example Forty-Nine). Right now each title is on a separate line in that text file. As in the example names, the titles start with a number, a period, and a space, followed by titles that contain spaces.

Does anyone know of a command I can use to create all twenty-four text files (of course initially empty) inside my one created course section titled folder? I don't know how I could do that from the options inside the File Explorer. There I have to go through selecting New Item from the Home tab on the top ribbon then go down to the Text Document and manually paste in or type one lecture item at a time. I'd much appreciate saving a lot of time.

Answer
Answer

Hi, I'm so pleased it worked.

>I do get this after each item created: New-Item: Access to the path 'C:\Users\ray\test' is denied.

Edit:: This can happen if there are blank lines in lectures.txt, to account for that use:

Get-Content -Path '.\lectures.txt' | ForEach-Object { if ($_.Trim().Length -gt 0) { New-Item -Path ".\$($_.Trim())"} }

>Maybe you can explain the command syntax a bit or give me a source where I can learn about it?

https://www.tutorialspoint.com/powershell/index.htm 

https://docs.microsoft.com/en-us/powershell/scripting/how-to-use-docs?view=powershell-7.2 

plenty of Googling :)

for Get-Content -Path '.\lectures.txt' | ForEach-Object { New-Item -Path ".\$($_)" }

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-content?view=powershell-7.2 

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/new-item?view=powershell-7.2 

If there's any particular part of the script you want an explanation for, let me know.

>If I could rate your reply, I'd give it a solid FIVE stars..

You can mark a reply as an answer by clicking Yes where it says 'Was this reply helpful'

________________________

GMT +11 hours

5 people found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated April 19, 2025 Views 5,964 Applies to: