任意の名前でフォルダを一気に作成する

vbsを実行した場所に任意のフォルダを作成するやつです。
配列の要素名を元にフォルダを作成されます。

とある作業で毎回同じフォルダを作る必要があり、手動で作るのが面倒なので初心者なりに作ってみました。

Option Explicit

Dim ObjFso
Dim strCurPath
Dim strFolderNames

'作成したいフォルダ名を記述する
strFolderNames = Array("FolderA", "FolderB", "FolderC", "FolderD", "FolderE")

Set ObjFso = createObject("Scripting.FileSystemObject")

Dim intLength
intLength = UBound(strFolderNames)

strCurPath = ObjFso.getParentFolderName(WScript.ScriptFullName) & "/"

Dim i
Dim strTargetPath
for i=0 to intLength

    strTargetPath = strCurPath & (i + 1) & "_" & strFolderNames(i)

    if not ObjFso.FolderExists(strTargetPath) Then

        ObjFso.CreateFolder(strTargetPath)

    end if
next

出力形式は
1_FolderA
2_FolderB
3_FolderC


という感じです。

strTargetPath変数の内容を変えれば連番とか消せます。

コメント

タイトルとURLをコピーしました