PowerShellを使って、ファイル名やフォルダ名を取得する方法です。
目次
フォルダ内のファイル名とフォルダ名をメモ帳に書き出す
- 名前を書き出すファイル名は「ichiran.txt」の場合
- 「ichiran.txt」は同じフォルダ内に保存する
(1)フォルダ内のフォルダ名とファイル名を取得したいフォルダを開きます。
(2)フォルダ内で右クリックし、Shiftキーを押しながら [ PowerShellウィンドウをここで開く ] を選択します。
![](https://officeqa.net/wp-content/uploads/2020/10/powershell-files-1.png)
→ PowerShellが開きます。
![](https://officeqa.net/wp-content/uploads/2020/10/powershell-files-2.png)
(3)「dir -name | out-file ichiran.txt」と入力し、Enterキーを押します。
![](https://officeqa.net/wp-content/uploads/2020/10/powershell-files-3.png)
以下をコピーし貼り付けてると簡単です。
dir -name | out-file ichiran.txt
![](https://officeqa.net/wp-content/uploads/2020/10/powershell-files-4.png)
(4)フォルダ内に保存された「ichiran.txt」を確認します。
![](https://officeqa.net/wp-content/uploads/2020/10/powershell-files-5.png)
「ichiran.txt」を開くとフォルダ内のフォルダ名とファイル名が書き出されています。
![](https://officeqa.net/wp-content/uploads/2020/10/powershell-files-6.png)
フォルダ名またはファイル名だけ書き出す
フォルダ名のみ書き出したい場合
dir -name -exclude *.* | out-file ichiran.txt
ファイル名のみ書き出したい場合
dir -name -include *.* | out-file ichiran.txt