0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ファイルのコピーを連番で1,000個つくるVBScript

Posted at

動作確認のためのテスト用PDFファイルを連番ファイル名で1000個作る必要があったので、VBScriptでやってみた。

連番deCopy.vbs
' 選択したファイルをこのスクリプトファイルに直接ドラッグするか、あるいは
' このスクリプトファイルを SendToフォルダに入れて、選択したファイルの
' 右クリックメニューで[送る]から実行する
Option Explicit

Dim file0, fName, startNum, lastNum, digit, padding, ext, i

file0 = WScript.Arguments(0)

fName = GetInput("連番より前のファイル名を入力してください。")
startNum = CLng(GetInput("連番の開始番号を入力してください。"))
lastNum = CLng(GetInput("連番の終了番号を入力してください。"))
digit = CLng(GetInput("連番の桁数を入力してください。"))

padding = String(digit, "0")

With CreateObject("Scripting.FileSystemObject")
    ext = "." & .GetExtensionName(file0)

    For i = startNum To lastNum
        .CopyFile file0, .BuildPath(.GetParentFolderName(file0), fName & Right(padding & i, digit) & ext)
    Next
End With
'// InputBox の入力値を返す

Function GetInput(ByVal msg)

    Dim val

    val = InputBox(msg)
    If IsEmpty(val) Then MsgBox("キャンセルされました。"): WScript.Quit
    If val = "" Then MsgBox "何も入力されていません。": WScript.Quit

    GetInput = val

End Function
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?