A realist in an ideological age

ゆとり世代が考えたこと,学んだことを記録するブログ

VBScriptで,日付の名前のついたフォルダを自動生成

新しいフォルダを作成し,フォルダ名を日付(例:190605)にすることがよくあります.これを自動生成してくれるスクリプトをメモ

dim objFSO
set objFSO = CreateObject("Scripting.FileSystemObject")

dim Cpath
dim strFolder
dim strDate
dim NewFilepass

strDate = Right(Date(),8)
strDate = Replace(strDate,"/","")

Cpath = objFSO.getParentFolderName(Wscript.ScriptFullname)

strFolder = objFSO.BuildPath(Cpath,strDate)
  If objFSO.FolderExists(strFolder) Then
     MsgBox "既に同名のフォルダが存在します"
  Else
     objFSO.CreateFolder(strFolder)
   End If

Set objFSO = Nothing