Folder names without spaces
How can I prevent the creation of folders with spaces in the name from within my script.
Define the path and new folder name to the function as parameters. Use the IndexOf method to check for spaces in the name and throw an exception if one is found. Just need a general check as one space is enough to stop the creation. While we are at it we will check that the path exists and that the name is not empty because
"".IndexOf(" ") returns –1 i.e. it doesn’t find any.
We can then use new-item to create the folder as normal