すみません。これは FTP に関する質問への回答ではなく、バッチ ファイルに関する議論です。私はそれについていくつかの詳細を見ます:
In accordance with your FOR command ("delims=_.-") and the name in the REN command, I assume that the format of your files is this:
TACOS_YYYY-Mon-DD_HH-MM-SS_UTC.csv
Where "Mon" is a three-letter month name, and that you want to rename to this format:
TACOS_YYYYMMDD_HHMMSS.csv
If this is true, then your REN command may cause an error because the asterisks imply several names! If you want to eliminate characters after TACOS, before YYYY, after DD and before HH, then this is not the way to do it. Perhaps the file names in your computer don't cause problems. Try to create two or more files with the same date and hour and different characters in the other places; in this case, the REN command try to rename two or more files with just one new name (unless you know that there is no way this happen).
SETLOCAL/ENDLOCAL のペアは役に立ちません。感嘆符が含まれている可能性のある名前の問題を回避したい場合は、%%A..%%F を展開するときに遅延展開を無効にする必要があります。名前に感嘆符が含まれている可能性がある場合は、プログラムを変更する必要があります。
3 文字の月を 2 桁に変換する別の方法を提案してもよろしいですか? このメソッドは、添字として 3 文字、配列要素の値として 2 桁の配列を使用するため、変換は即時に行われます。
@echo off
setlocal EnableDelayedExpansion
rem Create the array for months conversion
set m=100
for %%A in (Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) do (
set /A m+=1
set mon[%%A]=!m:~-2!
)
for /f "tokens=2-7 delims=_.-" %%A in ('dir /B TACOS_*') do (
ren TACOS*_*%%A-%%B-%%C*_*%%D-%%E-%%F_UTC.csv TACOS_%%A!mon[%%B]!%%C_%%D%%E%%F.csv
)
REN コマンドでアスタリスクを配置した場所にあるいくつかの文字を削除したい場合は、それらの文字を分離する方法を教えてください。たとえば、1 つの名前が次で始まる場合:
TACOSxyz_abcYYYY-Mon-DD...
次に、FOR コマンドの %%A が「YYYY」ではなく「abcYYYY」であることを認識する必要があります。
編集:以下に可能な解決策があります:
@echo off
setlocal EnableDelayedExpansion
rem Create the array for months conversion
set m=100
for %%A in (Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) do (
set /A m+=1
set mon[%%A]=!m:~-2!
)
for /f "tokens=2-7 delims=_.-" %%A in ('dir /B TACOS_*') do (
set YYYY=%%A
set DD=%%C
set HH=%%D
set SS=%%F
ren TACOS*_*%%A-%%B-%%C*_*%%D-%%E-%%F_UTC.csv TACOS_!YYYY:~-4!!mon[%%B]!!DD:~0,2!_!HH:~-2!%%E!SS:~0,2!.csv
)