Jump to content

Recommended Posts

Posted

I'm trying to create a directory based on an argument provided to a batch file.

 

For example, if I do the following: makedirectory.bat newdir

 

Which runs the line: md \path\to\directory\%1 (or %~1)

 

throws a "cannot create directory" error.

 

whereas: md \path\to\directory\newdir

 

works fine. It's nothing to do with permissions, I'm simply missing something obvious.

 

Any ideas?

Posted

Just tried this myself using the following in a batch file:

 

md c:\Intel\%1

 

Saved the file as c:\makedir.cmd and then ran c:\makedir.cmd test

 

It created c:\Intel\test without any errors. Are you sure you have the path written correctly??

Posted
It works if I use a static name instead of the variable, so the path must be correct. If I echo the argument, it shows up as correct. All very strange....
Posted

Ok, update. I've got my script working. Bit more background to it, as it's longer than I hinted at initially.

 

The script takes two arguments. The first is the yeargroup, the second is the directory name to create. Basically it loops through pupil workspaces, creating a folder structure and copying some files into that structure.

 

If I use the yeargroup as the first argument, and directory name as the second, it gives the above error. However, if I swap the argument positions around (and change the variables around in the script) it works without issue. I still don't know why it doesn't work in the first instance.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...