Create folder for entries in text file, and generate url.

I am working on a refinement for a process - we pull a text file with a list of dates.

Each date gets its own folder, and each date is used in a URL after to pull data for that date.

EX: List of dates is


We then create a directory for each

mkdir 2019-03-31.957
mkdir 2019-03-30.956
mkdir 2019-03-29.955

And put the URL for each after.

./curl.exe --url "https://some/url/date=2019-03-31.957 | out-file -encoding utf8 “F:\output\2019-03-31.957”



What I want to do, however, is pull from the text file the list of dates, create a folder for each, and then have the URL generate according to that list as well. I know I cannot do this with a static variable, and may possibly use a foreach loop, but this is way beyond me. Any advice or help is appreciated!




I have found something similar, and it looks like I can tweak it.

However, I’m definitely stumped on creating the unique URL using each line as a variable.

get-content $datelist | %{
mkdir “$folder$_”;

$textDate=(get-content MyListofDates.txt)

foreach ($d in $textDate){
new-item -itemtype directory $d
./curl.exe –url "https://some/url/$d" | out-file -encoding utf8 "F:\output\$d"



You’re made of magic, senor.

I was just editing in my proposed solution for the folders, but the URL problem was beyond me.

Is the $d variable powershell logic, or does it need to be predefined?


-edit, answered my own question. $d is a shorthand variable name for the built-in $date variable. Nice. Thanks again!


You’re more than welcome.

When I was first learning powershell the foreach loop was like a watershed moment for me. It just made more sense after that.

Edit to add:

The $d has nothing to do with a built in $date.

Before the foreach loop we build a variable ($textDate) with content from your text file. (you can type in $textdate.count to see how many elements are in it). Then in the foreach loop we tell it for every item ($d) in $textdate do {something}.


I could have also called it foreach ($potato in $textDate){write-host $potato} to get the same effect.

I might have yelled “Eureka” out loud in the office when I modified it, ran it, and it started doing things automatically.



And - okay, so the logic I’m seeing is that you are telling it, and it understands regardless of the name, that for each $item in $mytextfile , do {thing }