さらに詳しい情報:

さらに詳しい情報:

ファイル名が日付になっているファイルのフォルダがあります。ファイル名を から に変更する必要がありmm-dd-yyyy.eXtensionますyyyy-mm-dd.eXtension

現在私が持っているものは次のとおりです:

03-31-2019.txt
03-31-2020.txt
03-31-2021.txt
03-31-2022.txt

望ましいのは次の通りです:

2019-03-31.txt
2020-03-31.txt
2021-03-31.txt
2022-03-31.txt

関数は理解していますrenが、最初の名前から派生したすべての異なる名前を一括で変更する方法がよくわかりません。調べてみたところ、単純な関数に関するヘルプは見つかりましたrenが、名前を並べ替えるだけのヘルプは見つかりませんでした。

以下は、私が見つけた、役に立つren、および追加の考えを与えるいくつかのものですが、それでもまだ必要なものではありません。

Windows cmd コマンドプロンプトでファイルの名前を変更するにはどうすればいいですか?
ファイル名にスペースが含まれているファイルの名前を変更するバッチ プログラムはありますか?

答え1

そのためには、GUI サードパーティ ソフトウェアを使用する方が簡単です。

スイスナイフ製品として使用できるのは、無料の 一括名前変更ユーティリティ 基本的にあらゆる種類の操作を実行できます。

正規表現を使用したデータは次のようになります。

ここに画像の説明を入力してください

答え2

変数の文字列操作を使用して、サブ文字列の希望する再グループ化に応じて名前のレイアウトを定義できます。

1.echo.Date   : %date%  
2.echo.Weekday: %date:~0,3%  
3.echo.Month  : %date:~4,2%  
4.echo.Day    : %date:~7,2%  
5.echo.Year   : %date:~10,4%  

ここに画像の説明を入力してください


@echo off 

for %%i in (??-*.txt)do set "_n=%%~ni" && =;(
    %ComSpec% /v /c "ren "%%~i" !_n:~6,4!-!_n:~0,2!!_n:~2,3!%%~xi" );=

  • 異なるファイルを走査し、eXtension 内だけ/排他的に走査するのではなく.txt、同じフォルダー内で実行する場合は、それ.bat自体への適用を無視し、bat 名で を使用せず"-"、次のループを試してください。
@echo off 

for /f delims^= %%i in ('dir /a:a /b *-*.*')do set "_n=%%~ni" && =;(
    %ComSpec% /v /c "ren "%%~i" !_n:~6,4!-!_n:~0,2!!_n:~2,3!%%~xi" );=

分離されたテスト提案の場合は、フォルダーを作成し、そのフォルダー内でこの bat を実行します。これにより、同じ名前のレイアウトでテスト用のファイルを作成し、サブ文字列を使用した操作の使用を監視/視覚化できるようになります。

@echo off 

:: Deleting/creating files for testing ::
cd /d "%~dp0" && 2>nul del /q /a .\*.txt
for %%i in (19,20,21,22)do cd.>03-31-20%%~i.txt

for /f delims^= %%i in ('dir /a:a /b *-*.*')do set "_n=%%~ni" & echo\ &&  =;(
    %ComSpec% /v /c "echo\// Original file name.eXtension = !_n!%%~xi"
    %ComSpec% /v /c "ren "%%~i" !_n:~6,4!-!_n:~0,2!!_n:~2,3!%%~xi" 
    %ComSpec% /v /c "echo\variable index from 6 get 4 places == !_n:~6,4!"
    %ComSpec% /v /c "echo\variable index from 0 get 2 places == !_n:~0,2!"
    %ComSpec% /v /c "echo\variable index from 2 get 3 places == !_n:~2,3!"
    %ComSpec% /v /c "echo\and put back original file eXtension == %%~xi"
    %ComSpec% /v /c "echo\// File renamed to: !_n:~6,4!-!_n:~0,2!!_n:~2,3!%%~xi" );=
  • 出力:
// Original file name.eXtension = 03-31-2019.txt
variable index from 6 get 4 places == 2019
variable index from 0 get 2 places == 03
variable index from 2 get 3 places == -31
and put back original file eXtension == .txt
// File renamed to: 2019-03-31.txt

// Original file name.eXtension = 03-31-2020.txt
variable index from 6 get 4 places == 2020
variable index from 0 get 2 places == 03
variable index from 2 get 3 places == -31
and put back original file eXtension == .txt
// File renamed to: 2020-03-31.txt

// Original file name.eXtension = 03-31-2021.txt
variable index from 6 get 4 places == 2021
variable index from 0 get 2 places == 03
variable index from 2 get 3 places == -31
and put back original file eXtension == .txt
// File renamed to: 2021-03-31.txt

// Original file name.eXtension = 03-31-2022.txt
variable index from 6 get 4 places == 2022
variable index from 0 get 2 places == 03
variable index from 2 get 3 places == -31
and put back original file eXtension == .txt
// File renamed to: 2022-03-31.txt

さらに詳しい情報:

関連情報