、あなたはあなたがこのようにバッチファイルでそれを実行します
' the file paths. hardcoded, but you could alternatively collect these via command line parameters
Const IN_PATH = "path\to\directory"
Const OUT_PATH = "path\to\another\directory"
' check that the directories exist. you could create them instead, but here
' it just throws an error as that's easier
dim fso: set fso = CreateObject("Scripting.FileSystemObject")
if not fso.FolderExists(IN_PATH) then
err.raise 1,, "Path '" & IN_PATH & "' not found"
end if
if not fso.FolderExists(OUT_PATH) then
err.raise 1,, "Path '" & OUT_PATH & "' not found"
end if
dim infolder: set infolder = fso.GetFolder(IN_PATH)
dim file
for each file in infolder.files
dim name: name = file.name
dim parts: parts = split(name, ".")
' we're expecting a file format of a.b.c.pdf
' so we should have 4 elements in the array (zero-indexed, highest bound is 3)
if UBound(parts) = 3 then
' rebuild the name with the 0th, 1st and 3rd elements
dim newname: newname = parts(0) & "." & parts(1) & "." & parts(3)
' use the move() method to effect the rename
file.move fso.buildpath(OUT_PATH, newname)
else
' log the fact that there's an erroneous file name
WScript.Echo "Unexpected file format: '" & name & "'"
end if
next 'file
のようなものを使用することができ、ログファイルに出力をリダイレクト
cscript rename-script.vbs > logfile.txt
これは、あなたが簡単に頼ることができることを前提としてい区切られた部分の書式の詳細ではなく、ファイル名の部分を区切る期間。
私はparts(1)
配列要素であると思う日付を並べ替えるには、それが特定の形式でだから、あなたは、単に文字列の各ビットを抽出することができます。
'date in format mmddyyyy
dim month_, day_, year_, date_
month_ = left(parts(1), 2)
day_ = mid(parts(1), 3, 2)
year_ = right(parts(1), 4)
date_ = year_ & month_ & day_ ' now yyyymmdd
ので、ファイル名を再構築、あなたは新しいフォーマットされた日付とparts(1)
を置き換えることができ
dim newname: newname = parts(0) & "." & date_ & "." & parts(3)
このスクリプトは完全に機能します。助けてくれてありがとう。私が使用しなかったのはログファイルのみでした。この最後の作品は私のオートメーションを完成させるはずです。再度、感謝します。 –
スクリプトのバリエーションをもう一度あなたの方法でスローすることができますか?私はこれらの名前が変更されたファイルを日付に基づいて並べ替えることができる必要があります。これを行う唯一の問題は、ファイル拡張子の日付部分が次の形式であることです。nnnnnnnnnnnnnnnn.dddddddd.pdfここで、ddddddddは(2009年1月23日)のようなものです。 2008年1月23日がある場合、これは日付に基づく順序でソートされません。これらを並べ替えるためには、最初の4日前の2009年または最後の4日を動かす必要があります。とにかくこれをやっているのが見えますか?別の区切り文字を持つ別のスクリプトを使用していますか? –
うわー!!!信じられない。完璧です。このスクリプトは、sooooに多くの時間を節約しようとしています。本当にありがとう。 –