header image

Test folders

Posted by: | March 28, 2009 | No Comment |

I needed some test folders in a hurry.  They didn’t have to have anything in them – just exist as a set of folders for me to work with.

From the PowerShell prompt

1..20 | foreach {md "test$_"}

How easy is that.  Twenty folders in the time it would take me to open Windows explorer. 

Use the range operator to define a range of suffixes and pipe into foreach.  The md command creates the folder using string substitution to append the suffix.

If you want to be slightly more formal about things then the Sunday best version of the command is

21..40 | foreach { New-Item -Name "test$_" -ItemType directory }

The range operator is a very useful tool that probably doesn’t get as much exposure as it should


Technorati Tags:

under: PowerShell original