0

ファイルの名前を変更するバッチファイルまたはvbscriptを作成する必要があります。ファイル名のすべてを2番目の「。」まで保持する必要があります。ただし、2番目のドットの後にあるものは削除してください。

これは、ファイル名がどのように見えるかのサンプルです。

nnnnnnnnnnnnnnnn.xxxxxxxx.dddddddddd.pdf 
  • n=16の数字0-9
  • x=この形式の日付ex:02232008
  • d= 10の数字0〜9、これは削除したいファイル名の部分です

上記のサンプルのdを削除する必要がありますが、残りのファイル名は同じままにします。このバッチファイルは、約3,000のpdfファイルを含むフォルダーで実行できる必要があります。同じフォルダに戻すことも、別のフォルダに出力することもできます。

4

3 に答える 3

1
FOR /F "USEBACKQ delims=. tokens=1-4" %%F IN (`DIR /B /A-D "C:\Path\To\PDFs\"`) DO (
  REN "%%~fF.%%G.%%H.%%I" "%%F.%%G.%%I"
)

ピリオドの数が異なるファイルがある場合は、単純な引数を追加して、ピリオド区切り文字がいくつ存在するかをカウントしてから実行する必要があります。

于 2011-08-17T13:56:14.480 に答える
0

In VBScript, you can use something like

' 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

You would run it in a batch file thus, redirecting output to a log file

cscript rename-script.vbs > logfile.txt

This assumes that you can simply rely on the period to delimit the parts of the file name rather than the specifics of the format of the delimited parts.


To rearrange the date, which I think is in the parts(1) array element, you can simply extract each bit of the string because it's in a specific format:

'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

so when rebuilding the filename, you can replace parts(1) with the new formatted date

dim newname: newname = parts(0) & "." & date_ & "." & parts(3)
于 2011-08-16T21:02:56.670 に答える
0

半自動の名前変更ツールであるStringSolverを使用して、最初のファイルの名前を変更し、一般化された名前変更に問題がないことを確認してから、他のすべてのファイルでそれを受け入れます。

> move 1234567890123456.02232008.1946738250.pdf 1234567890123456.02232008.pdf

説明を得る:

> move --explain

the file name until the end of the second number + the extension

move --auto満足している場合は、または簡潔なバージョンを使用して半自動ツールを実行できます。

> move

免責事項:私は学術目的で作成されたこの自由ソフトウェアの共著者です。

于 2014-02-14T10:40:13.817 に答える