Making directories on a network share

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
skiflirt
Posts: 2
Joined: 28 Nov 2014 17:01

Making directories on a network share

#1 Post by skiflirt » 20 Nov 2015 19:54

I've run into an issue that my IT group hasn't been able to fix so far. When attempting to create a directory on one of our network servers (it's a netapp device) it will throw an error because it won't create all of the intermediate or parent directories. I've checked to ensure that command extensions are enabled (via SETLOCAL ENABLEEXTENSIONS) in my batch file.

For example: \\networkshare\dir1\dir2\dir3\dir4 where the \\networkshare\dir1 already exists returns a "The directory or file cannot be created." error message. If I create each directory, dir2, then dir3 and finally dir4 individually everything works fine.

So what I'd like to do, short of them fixing it on the server side, is to create a function in my script that I can call that will check to see if each individual directory exists and if not, then create it. I thought that the "for /r" loop would be a place to start but so far I've not

pseudo code:
Passing a UNC path as an argument e.g. \\networkshare\dir1\dir2\dir3\dir4

Code: Select all

loop through each directory (
    check to see if it exists
        if not, create it
    otherwise loop
)


Any ideas would be greatly appreciated!

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Making directories on a network share

#2 Post by Squashman » 21 Nov 2015 08:28

The first thing I would try before breaking up the path is this.

Code: Select all

pushd \\server\share
md dir1\dir2\dir3
popd

Post Reply