0

I have a Dir Command I use to make a text list of a directory of files.. "dir /a /b /-p /o:gen > z-file_list.txt"

Dose anyone know how I can change this so the text list dose not contain any extensions? So just the filename?

Thanks in advance!

  • EDIT -

Sorry I wasn't clear. What I mean is that his command will save a txt file with a file list of the contents of the directory.

The text file will look like this
filename.ext
filename.ext
filename.ext
filename.ext

I am trying to work out how to get the text file to look like this.
filename
filename
filename
filename

Thanks.. sorry I was unclear.

4
  • Just remove ".txt" from the file name string?
    – Ramhound
    Commented Sep 24, 2016 at 2:02
  • that is just the file it is writing into, the data is saved in "z-file_list.txt". It dose not effect the dir command.
    – aJynks
    Commented Sep 24, 2016 at 2:07
  • Your question does not make sense. You asked how to generate a file without an extension.
    – Ramhound
    Commented Sep 24, 2016 at 2:13
  • oh, sorry. I have edited the question in the hopes of making it more clear.
    – aJynks
    Commented Sep 24, 2016 at 3:47

2 Answers 2

4

The dir command does not have a switch or option to drop extensions.

It can be done by processing the output of dir /b in a for /f loop, though.

(del list.txt 2>nul) & for /f %f in ('dir /a /b /o:gen') do @echo %~nf >>list.txt

If you don't care about subdirectories or system/hidden files (which is what dir /a is for) then a plain for would work, too.

(del list.txt 2>nul) & for %f in (*) do @echo %~nf >>list.txt

Run dir /?, del /? and for /? for more details on the syntax and switches.

0

You can do it from the CMD prompt with a little cheating with Powershell. From the command prompt, type the follwing:

powershell -command "dir |select basename" > file_list.txt

As I said, this is a bit of a cheat, as powershell -command invokes the Powershell shell to run the Powershell script dir |select basename". FYI, dir in Powershell is just an alias for the command get-childitem and has nothing to do with the CMD prompt's dir command. Powerhsell exectues that script and the results are returned to the CMD prompt and redirected (>) to the text file.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .