Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

mkdir in wshshell.run

1,018 views
Skip to first unread message

shee...@yahoo.com

unread,
Jan 21, 2008, 9:25:08 AM1/21/08
to
I have a script that is creating a whole directory structure that
doesn't exist, using the mkdir command. The script issues this simple
command:

backupdir = c:\migrations\backups\13833
relativepath = \sys3\sheel

wshshell.run mkdir & " " & backupdir & relativepath

when I echo out the command, it appears to build out the command
correctly, but when I go to execute it, it says "The system cannot
find the file specified"

Is it not finding the "mkdir" executable?

Thanks,
Sheel

Pegasus (MVP)

unread,
Jan 21, 2008, 9:34:40 AM1/21/08
to

<shee...@yahoo.com> wrote in message
news:db6c06b3-b557-45d6...@s19g2000prg.googlegroups.com...

"mkdir" is a command that is internal to the Command Processor.
To invoke it from another program such as cscript, you must
launch it through the command processor like so:

cmd /c mkdir

I wonder why you would want to create a folder in this way.
Doing it directly from a batch file would be simpler, or using
the VB Script function

objFSO.CreateFolder(FolderName)

would be much cleaner than the hybrid you currently have.


Tom Lavedas

unread,
Jan 21, 2008, 11:12:10 AM1/21/08
to
On Jan 21, 9:34 am, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:
> <sheel...@yahoo.com> wrote in message

One reason I can think of to do it this was is related to the fact
that mkdir (md) can create multiple folder levels with one pass. The
logic required in a script is significantly more complicated.

For example, this script can be installed for doing this from the
Right-click menu ...

with createobject("scripting.filesystemobject")
if Wscript.Arguments.Count = 0 Then
sPath = .GetFolder(".").Path
Else
sPath = Wscript.Arguments.Item(0)
End if
sNewName = inputbox("New Folder Name:", "Create Folder")
for each name in Split(sNewname, "\")
sPath = sPath & "\" & name
if Not .FolderExists(sPath) Then .CreateFolder(sPath)
next
createobject("WScript.Shell").Run "explorer " & sPath
end with

The Right-click menu is accomplished with the following registry
entry ...

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Folder\shell\NewFolder\command]
@="wscript.exe \"C:\\Documents and Settings\\%username%\\My Documents\
\Scripts\\NewFolder.vbs\" \"%1\""

Note that the default value after the @= needs to be all on one line.
Also, the location of the NewFolder.vbs script is arbitrary, but needs
to be reflected in the registry entry.

I actually use a much more complicated version of this that performs a
self-registration on first execution, displays a character
representation of the folder tree and supports multiple tree branches
in a single invocation of the procedure. I'll see if I can get it
posted on my web site today, in case anyone would care to have a look.

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/

shee...@yahoo.com

unread,
Jan 21, 2008, 12:27:07 PM1/21/08
to
> ===========http://members.cox.net/tglbatch/wsh/- Hide quoted text -
>
> - Show quoted text -

Tom,

You hit the nail right on the head. The reason I'm using that is
because I am creating multiple levels, not just the last level.

Thanks for your help!

Sheel

Charles E Finkenbiner

unread,
Jan 22, 2008, 9:29:59 AM1/22/08
to

Hi,

If you want a VBScript solution then this is the code I use:

sPath = "r:\xxx\yyy\zzz\" ' Trailing \ is required
iPos = InStr(4, sPath, "\", 0) ' Skip drive letter check
Set oFSO = CreateObject("Scripting.FileSystemObject")
While(iPos <> 0)
If(Not(oFSO.FolderExists(Left(sPath, iPos)))) Then
oFSO.CreateFolder(Left(sPath, iPos))
End If
iPos = InStr(iPos+1, sPath, "\", 0)
Wend
Set oFSO = Nothing


Hope this helps,

CEF

0 new messages