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?

More than 5 years have passed since last update.

PowerShellでファイル一覧出力

Last updated at Posted at 2018-10-25

シンプルなファイル一覧出力

カレントディレクトリ配下のファイル一覧を再帰的にテキスト出力します。ディレクトリのみの行は除外しています。
PowerShell Core 6.1でもこの程度ならコードの修正も必要ないですね。

sample.ps1
$dateTime = Get-Date -Format "yyyyMMdd_hhmmss"
$fileName = "fileList_" + $dateTime.ToString() + ".txt"
ls -Recurse | %{
    if($_.Mode -ne "d-----"){
        $_.FullName | Out-File -FilePath $fileName -Encoding "UTF8" -Append -Width 260
    }
}

以下は実行結果の例です。

fileList_20181026_072227.txt
C:\Users\sample\hoge\main.py
C:\Users\sample\hoge\sub.py
C:\Users\sample\hoge\pic.png
C:\Users\sample\hoge\.vscode\launch.json
C:\Users\sample\hoge\.vscode\settings.json
C:\Users\sample\hoge\.vscode\tasks.json
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?