0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

欠けてる番号を探したい

Last updated at Posted at 2024-11-25

番号のファイルが多くて何番が足りないか分からない時があるので作成した

@echo off
setlocal enabledelayedexpansion

REM 連番の数字を保持する配列
set "numbers="

REM 現在のディレクトリ内のファイルを取得
for %%F in (*.txt) do (
    REM ファイル名から数字部分を抽出
    for /f "tokens=* delims=" %%A in ("%%~nF") do (
        REM 最後のアンダースコア以降の部分を取得
        for /f "tokens=* delims=_" %%B in ("%%A") do (
            set "lastPart=%%B"
        )
        REM 数字のみか確認
        for /f "tokens=* delims=0123456789" %%C in ("!lastPart!") do (
            if "%%C"=="" set "numbers=!numbers! !lastPart!"
        )
    )
)

REM 配列をソート(数値として)
for %%N in (!numbers!) do (
    set /a num[%%N]=1
)

REM 連番チェック
set "missing="
for /l %%I in (1,1,99) do (
    if not defined num[%%I] (
        set "missing=!missing! %%I"
    )
)

REM 結果を表示
if defined missing (
    echo 足りない番号: %missing%
) else (
    echo 連番はすべて揃っています。
)
pause
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?