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
"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.
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/
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
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