2
1

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 5 years have passed since last update.

VBSでフォルダをコピーする方法

Last updated at Posted at 2018-10-04

VBSでフォルダをコピーする方法について記載します

概要

VBScriptを使ってフォルダをコピーする方法について記載します。

ソースコード

以下のソースコードをメモ帳で書いて「.vbs」という拡張子で保存します。

.vbs
Option Explicit
On Error Resume Next

Dim FSO            'FileSystemObject'
Dim CopyFromFolder 'コピー元フォルダ名'
Dim CopyToFolder   'コピー先フォルダ名'

CopyFromFolder = "コピー元フォルダ名のパス"
CopyToFolder = "コピー先フォルダ名のパス" 

Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
If Err.Number = 0 Then
    'コピー先フォルダが存在しないときは作成する
    If FSO.FolderExists(CopyToFolder) <> True Then
        FSO.CreateFolder(CopyToFolder)
    End If

    'フォルダコピー
    FSO.CopyFolder CopyToFolder, CopyFromFolder, True
    If Err.Number = 0 Then
        WScript.Echo "データをコピーしました。"
    Else
        WScript.Echo "エラー: " & Err.Description
    End If
Else
    WScript.Echo "エラー: " & Err.Description
End If

Set FSO = Nothing

使い方

vbsファイルを開くだけで処理が実行されます。

2
1
1

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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?