Last active
December 25, 2015 05:07
-
-
Save motoraku/1b96ed0e8e28061829a0 to your computer and use it in GitHub Desktop.
Windows 右クリックからファイルに日時を付与してコピー : Copy file with date and time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| '1.オプション指定 | |
| Option Explicit | |
| '2.変数宣言 | |
| Dim fsObj | |
| Dim strFileName | |
| Dim strNewFileName | |
| Dim strParentFolderName | |
| Dim strBaseName | |
| Dim ext | |
| '3.引数のチェック | |
| If WScript.Arguments.Count <> 1 Then WScript.Quit | |
| '4.ファイル名取得 | |
| strFileName = WScript.Arguments(0) | |
| '5.ファイルシステムオブジェクトを取得 | |
| Set fsObj = CreateObject("Scripting.FileSystemObject") | |
| '6.ファイルの拡張子取得 | |
| ext = LCase(fsObj.GetExtensionName(strFileName)) | |
| '7.ファイルのベース名取得 | |
| strBaseName = fsObj.GetBaseName(strFileName) | |
| '8.ファイルの親フォルダ名取得 | |
| strParentFolderName = fsObj.GetParentFolderName(strFileName) | |
| '9.日付日時を付与したファイル名を作成 | |
| strNewFileName = _ | |
| strParentFolderName & _ | |
| "\" & strBaseName & "_" & _ | |
| Right("0" & Year(Now), 4) & Right("0" & Month(Now), 2) & Right("0" & Day(Now), 2) & "-" & _ | |
| Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2) & Right("0" & Second(Now), 2) & _ | |
| "." & ext | |
| '10.コピー処理 | |
| fsObj.CopyFile strFileName, strNewFileName, true | |
| '11.終了処理 | |
| set fsObj = Nothing | |
| set strFileName = Nothing | |
| set strNewFileName = Nothing | |
| set strParentFolderName = Nothing | |
| set strBaseName = Nothing | |
| set ext = Nothing | |
| WScript.Quit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment