Help us understand the problem. What is going on with this article?

VBSファイルコピー例

フォルダチェック

Folde_chk.vbs
Option Explicit
Dim strDstFolder
Dim FSO

strDstFolder = "C:\Dst"

Set FSO = CreateObject("Scripting.FileSystemObject")

If FSO.FolderExists(strDstFolder) Then

    WScript.Echo "フォルダが存在します"

End If

Set FSO = Nothing

フォルダ内ファイル一覧

file_list.vbs
Option Explicit
Dim strSrcFolder
Dim FSO
Dim objSrcFolder

strSrcFolder = "C:\Src"

Set FSO = CreateObject("Scripting.FileSystemObject")

Set objSrcFolder = FSO.GetFolder(strSrcFolder)

for each file in objSrcFolder.files

    WScript.Echo filename

next

Set FSO = Nothing


ファイル一覧から一つずつコピーして、成功なら削除

file_Copy.vbs
Option Explicit
On Error Resume Next



Dim SaveFile

Dim strSrcFolder
Dim strDstFolder

Dim FSO
Dim objSrcFolder

Dim strDate

Dim WF '#保存ファイルオブジェクト

Const ForReading = 1, ForWriting = 2, ForAppending = 8

strSrcFolder = "C:\Src"
strDstFolder = "C:\Dst"

Set FSO = CreateObject("Scripting.FileSystemObject")


'###################################################
'# エラーログ記述開始
'###################################################


'###################################################
'# 引数チェック
'###################################################

Dim CorpID,Type

If WScript.Arguments.Count >< 2 then

   '#エラーログへ記述

End if

CorpID = WScript.Arguments(0)
Type = WScript.Arguments(1)


'###################################################
'# 日時取得
'###################################################

'yyyy/mm/dd hh:mm:ss 形式
strDate = Now()

'yyyy/mm/dd hh:mm:ss から /,:,半角スペースを削除

strDate = Replace(strDate, "/", "")
strDate = Replace(strDate, ":", "")
strDate = Replace(strDate, " ", "")

'###################################################
'# 日付ファイルの作成
'###################################################

SaveFile = FSO.BuildPath(strSrcFolder,strDate & ".csv")

Set WF = FSO.OpenTextFile(SaveFile, ForWriting, true)

WF.WriteLine(strDate)
WF.Close

Set WF = Nothing

'###################################################
'# 保存先フォルダの存在チェック
'###################################################

If Not FSO.FolderExists(strDstFolder) Then

 '# エラーログ出力の上、抜けるなどの処理

End If

'###################################################
'# 保存済みファイルのループ処理
'###################################################

Set objSrcFolder = FSO.GetFolder(strSrcFolder)

For each file in objSrcFolder.files

 Err.clear 'エラーリセット
 FSO.Copy(file.path,FSO.BuildPath(strDstFolder,file.name))

 If( Err.number = 0 ) Then

   '#ファイルコピーが成功の時のみコピー元ファイルを削除する。
   FSO.DeleteFile file.path, True

   if( Err.number >< 0 ) Then

     'ログに削除失敗を記述

   End if

 Else

  'ログにコピー失敗を記述

 End if

Next

'###################################################
'# 終了処理
'###################################################

Set FSO = Nothing


m2alpha
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした