フォーラムへの最初の投稿であった私の最後の投稿は、確認する前に閉じられたので、ここでもう一度詳細に質問します。
Const SrcFilePath = "C:\Folder 1\Temp\"
WScript.echo "SrcFilePath = " & SrcFilePath
Const FileExtension = ".txt"
newdate = date()-1
Set fso = CreateObject("Scripting.FileSystemObject")
If Day(newdate)>9 Then
ExtensionDay = Day(newdate)
Else
ExtensionDay = "0"&Day(newdate)
End If
If Month(newdate)>9 Then
ExtensionMonth = Month(newdate)
Else
ExtensionMonth = "0"&Month(newdate)
End If
If Year(newdate)>9 Then
ExtensionYear = Year(newdate)
Else
ExtensionYear = Year(newdate)
End If
Mon = MonthName(ExtensionMonth, true)
Yer = Right(ExtensionYear,2)
DateTag = ExtensionDay & "_" & ExtensionMonth & "_" & ExtensionYear
DateTag1 = ExtensionYear
DestFileName = "Test File_" & DateTag & FileExtension
WScript.echo DestFileName
SrcFile = SrcFilePath & "Test File_" & DateTag & FileExtension
Dest_File = "D:\Test 1\" & ExtensionYear & "\"
WScript.echo "Copy from =" & SrcFile, "Copy to =" & Dest_File
Fso.CopyFile SrcFile, Dest_File
上記のコードは、ファイル名に昨日の日付が含まれるファイルを取得し、そのファイルから年を含むフォルダーに移動します。
これが私がやりたいことです
「C:\Folder 1\Temp\」フォルダ内に以下のファイルがあります
C:\フォルダ 1\Temp\Test 1_2012_10_25.txt
C:\フォルダ 1\Temp\テスト 2_2013_08_25.txt
C:\フォルダ 1\Temp\Test 3_2011_10_25.txt
C:\フォルダ 1\Temp\Test 4_2010_10_25.txt
これらのファイルを、以下のようにファイル名とファイル名から年に基づいてフォルダに移動してください。上記の私のコードは、昨日の日付に対して 1 つのファイルのみを実行します。フォルダー内のすべてのファイルをループして整理したいと思います。
C:\Folder 1\Temp\Test 1_2012_10_25.txt > D:\Test 1\2012\ テスト 1_2012_10_25.txt
C:\Folder 1\Temp\Test 2_2013_08_25.txt > D:\Test 2\2013\ テスト 2_2013_08_25.txt
C:\Folder 1\Temp\Test 1_2012_10_25.txt > D:\Test 3\2011\ テスト 3_2012_10_25.txt
C:\Folder 1\Temp\Test 1_2012_10_25.txt > D:\Test 1\2012\ テスト 1_2012_10_25.txt
また、D:\ のフォルダーが存在しない場合は、それらを作成します。
ありがとう