帮助使用 VBScript 在 Windows 中创建 Folder1/Folder2(这两个文件夹以前都不存在,我的意思是创建多级文件夹 @ a strech.) [英] Help To create Folder1/Folder2 in Windows using VBScript ( Both the folders not exists before, i mean to create multilevel folders @ a strech.)

查看:43
本文介绍了帮助使用 VBScript 在 Windows 中创建 Folder1/Folder2(这两个文件夹以前都不存在,我的意思是创建多级文件夹 @ a strech.)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用我的 VBscript 创建了文件夹.当我给出一个文件夹路径时,脚本只创建最后一个文件夹,如果最后一个文件夹不存在,它将失败......我需要一个 vbscript 代码来一次性创建整个文件夹结构.就像 unix 中的 mkdir -p

I have created folders using my VBscript. when i give a folder path, the script is creating only the last folder, if the last but one folder does not exists, it will fail... I need a vbscript code to create the entire folder structure on the single go. like mkdir -p in unix

推荐答案

你可以使用这个功能:

Const PATH = "X:\folder0\folder1\folder2"

Set fso = CreateObject("Scripting.FileSystemObject")

BuildFullPath PATH

Sub BuildFullPath(ByVal FullPath)
    If Not fso.FolderExists(FullPath) Then
        BuildFullPath fso.GetParentFolderName(FullPath)
        fso.CreateFolder FullPath
    End If
End Sub

或者简单地从您的脚本中调用 mkdir 命令:

Or simply call the mkdir command from your script:

Set objShell = CreateObject("Wscript.Shell")
objShell.Run "cmd /c mkdir X:\folder1\folder2\folder3"

这篇关于帮助使用 VBScript 在 Windows 中创建 Folder1/Folder2(这两个文件夹以前都不存在,我的意思是创建多级文件夹 @ a strech.)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆