![](https://officeqa.net/wp-content/uploads/2020/09/cmd_get-filename-foldername-cmd-1024x614.jpg)
コマンドプロンプトを使って、ファイル名やフォルダ名を取得する方法です。
パソコン操作が得意ではない場合は他の方法を試してみてください。
目次
コマンドプロンプトを起動する
(1)キーボードの「Windowsロゴ」キーを押してから、「R」キーを押します。
→「ファイル名を指定して実行」が起動します。
’(2)テキストボックス内に「cmd」と入力し、「Enter」キーを押します。
![](https://officeqa.net/wp-content/uploads/2020/10/cmd-files-ichiran-shutoku-1.png)
cd /d f:
フォルダ内のファイル名とフォルダ名をメモ帳に書き出す
- 名前を取得したいフォルダはドライブ割り当てをしている「F:¥sample」
- 名前を書き出すファイル名は「ichiran.txt」の場合
- 「ichiran.txt」は同じフォルダ内に保存する
![](https://officeqa.net/wp-content/uploads/2020/10/windows10-filename-1.png)
フォルダ名とファイル名
(1)コマンドプロンプトを起動し、フォルダ名とファイル名を取得したいフォルダへ移動します。
![](https://officeqa.net/wp-content/uploads/2020/10/cmd-files-ichiran-shutoku-2.png)
次のように入力しても移動できます。
cd /d f:/sample
(2)「dir /b > ichiran.txt」と入力し、Enterキーを押します。
dir /b > ichiran.txt
保存されたファイルを確認するとフォルダ名とファイル名が書き出されています。
![](https://officeqa.net/wp-content/uploads/2020/10/cmd-files-ichiran-shutoku-3.png)
フォルダ名またはファイル名
フォルダ名のみ書き出したい場合
dir /b /ad > ichiran.txt
ファイル名のみ書き出したい場合
dir /b /a-d > ichiran.txt