Skip to content

Instantly share code, notes, and snippets.

@ShortArrow
Created August 19, 2025 23:25
Show Gist options
  • Save ShortArrow/47eebd60b2d4592017f83e365a1a82d1 to your computer and use it in GitHub Desktop.
Save ShortArrow/47eebd60b2d4592017f83e365a1a82d1 to your computer and use it in GitHub Desktop.
How to delete special path in Windows

Windowsで特殊な削除方法が必要なファイル名一覧

予約デバイス名

ファイル名 説明 削除コマンド例
CON コンソール Remove-Item -LiteralPath "\\?\$pwd\CON" -Force
PRN プリンター Remove-Item -LiteralPath "\\?\$pwd\PRN" -Force
AUX 補助デバイス Remove-Item -LiteralPath "\\?\$pwd\AUX" -Force
NUL Nullデバイス Remove-Item -LiteralPath "\\?\$pwd\NUL" -Force
COM1COM9 シリアルポート Remove-Item -LiteralPath "\\?\$pwd\COM1" -Force
LPT1LPT9 パラレルポート Remove-Item -LiteralPath "\\?\$pwd\LPT1" -Force

末尾に特殊文字があるファイル名

ファイル名例 問題点 削除コマンド例
filename 末尾スペース Remove-Item -LiteralPath "\\?\$pwd\filename " -Force
filename. 末尾ピリオド Remove-Item -LiteralPath "\\?\$pwd\filename." -Force
filename... 複数の末尾ピリオド Remove-Item -LiteralPath "\\?\$pwd\filename..." -Force
file 複数の末尾スペース Remove-Item -LiteralPath "\\?\$pwd\file " -Force

禁止文字を含むファイル名(通常作成不可)

文字 説明 削除コマンド例(もし存在した場合)
< 小なり記号 Remove-Item -LiteralPath "\\?\$pwd\file<name" -Force
> 大なり記号 Remove-Item -LiteralPath "\\?\$pwd\file>name" -Force
: コロン(ドライブ文字以外) Remove-Item -LiteralPath "\\?\$pwd\file:name" -Force
" ダブルクォート Remove-Item -LiteralPath '\\?\$pwd\file"name' -Force
| パイプ Remove-Item -LiteralPath "\\?\$pwd\file|name" -Force
? 疑問符(ワイルドカード) Remove-Item -LiteralPath "\\?\$pwd\file?name" -Force
* アスタリスク(ワイルドカード) Remove-Item -LiteralPath "\\?\$pwd\file*name" -Force

その他の問題のあるケース

ケース 説明 削除コマンド例
260文字超のパス MAX_PATH制限超過 Remove-Item -LiteralPath "\\?\C:\very\long\path\...\file.txt" -Force
con.txt 予約名+拡張子 Remove-Item -LiteralPath "\\?\$pwd\con.txt" -Force
nul.log 予約名+拡張子 Remove-Item -LiteralPath "\\?\$pwd\nul.log" -Force

代替削除方法

方法 コマンド 用途
PowerShell (.NET) [System.IO.File]::Delete("\\?\$pwd\nul") Remove-Itemが失敗した場合
コマンドプロンプト cmd.exe /c del "\\?\%cd%\nul" PowerShellから実行
絶対パス指定 Remove-Item -LiteralPath "\\?\C:\full\path\to\nul" -Force パスが明確な場合

注意:

  • 予約デバイス名は大文字小文字を区別しない(NUL = nul = Nul)
  • \\?\プレフィックスはWindowsのパス解析をバイパスする
  • Windows 10/11では長いパスのサポートが改善されているが、レジストリ設定が必要な場合がある
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment