+ Post New Thread
Results 1 to 4 of 4
Windows Thread, batch file behaviour in Technical; I'm trying to create a directory based on an argument provided to a batch file. For example, if I do ...
  1. #1

    Join Date
    Nov 2006
    Posts
    998
    Thank Post
    132
    Thanked 58 Times in 51 Posts
    Rep Power
    25

    batch file behaviour

    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?

  2. #2
    themightymrp's Avatar
    Join Date
    Dec 2009
    Location
    Leeds, West Yorkshire
    Posts
    1,258
    Thank Post
    218
    Thanked 232 Times in 200 Posts
    Rep Power
    74
    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??

  3. #3

    Join Date
    Nov 2006
    Posts
    998
    Thank Post
    132
    Thanked 58 Times in 51 Posts
    Rep Power
    25
    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....

  4. #4

    Join Date
    Nov 2006
    Posts
    998
    Thank Post
    132
    Thanked 58 Times in 51 Posts
    Rep Power
    25
    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.

SHARE:
+ Post New Thread

Similar Threads

  1. batch file to shutdown PCs
    By macca in forum Windows
    Replies: 5
    Last Post: 3rd May 2007, 09:20 AM
  2. prezzie batch file to collect dps logs
    By russdev in forum ICT KS3 SATS Tests
    Replies: 4
    Last Post: 16th May 2006, 12:16 PM
  3. batch file help
    By beeswax in forum Scripts
    Replies: 9
    Last Post: 3rd March 2006, 07:48 PM
  4. numbers and batch files
    By russdev in forum Windows
    Replies: 4
    Last Post: 19th November 2005, 09:51 PM
  5. Blocking Batch Files using Group Policy in Server 2003
    By markwilliamson2001 in forum Windows
    Replies: 13
    Last Post: 4th October 2005, 05:28 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •