VBScriptメモ「ファイル操作」

ファイルの存在チェック

Option Explicit

Dim strPath 
strPath = "c:\work\test.pdf"

If CreateObject("Scripting.FileSystemObject").FileExists(strPath) Then
    MsgBox("ファイル有!")
Else
    MsgBox("ファイル無!")
End If

ファイルのコピー


Option Explicit

Dim FSO 'ファイルシステムオブジェクト

Dim strFromPath 'コピー元ファイルパス
strFromPath = "c:\work\test.pdf"
Dim strToPath 'コピー先ファイルパス
strToPath = "c:\work\testCopy.pdf"

Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.CopyFile strFromPath,  strToPath , True
Set FSO = Nothing

ファイルの移動


Option Explicit

Dim FSO
Dim strFromPath '移動元元ファイルパス
Dim strToPath '移動先ファイルパス

strFromPath = "c:\work\test.pdf"
strToPath = "c:\work\testCopy.pdf"

Set FSO = CreateObject("Scripting.FileSystemObject")

FSO.MoveFile strFromPath, strToPath

Set FSO = Nothing

0 件のコメント :

コメントを投稿