r/commandline•
brail

[windows 7] trying to get a list of file names...

I need to get a list of all file names in a folder. I found dir /b > print.txt which was good but not perfect, as I only want the file names themselves but it prints the file names and types. So instead of "image_1" it gives "image_1.png" which is annoying.

I found a thing on the googles that I thought would be helpful, a microsoft fixit that you run and would add a context menu for right clicks, but it does not do what I want it to at all.

@echo off dir %1 /-p /o:gn > "%temp%\Listing" start /w notepad /p "%temp%\Listing" del "%temp%\Listing" exit

I dont know what that mess means to edit it or how to remove it now.

If there is no command line to get the file names without the .png then my next best goal would be to edit the context command to do /dir text thing rather than trying to print it through a printer.

Thanks in advance for any help

Posted Jan 19, 2016, 11:24 PM UTC

517
weisbrot•

the extension is part of the filename, windows' filemanager just doesn't display it. actually i don't know and that's just how it is in linux/unix.

3
willrandship•

It's the same way in windows, yes.

Filenames in windows are just parsed from the back to find the last period, then everything that follows is an "extension". Linux uses the same technique, but usually inspects the files to try to guess what the type is first.

1
teh_lux•

wow we've arrived at the point where people began thinking that the filename of "readme.txt" is "readme" and the extension is seperate from that..

thanks microsoft, idiots.

instead of not showing extensions, they just should have done it how nautilus does it. when renaming the extension isn't automatically selected.

1
ashtrae•

Microsoft does this. However I agree that the extensions shouldn't be hidden by default. It be great if a general user knew that a .bat file could harm their PC.

1
ashtrae•

Here is something in powershell. Just cd to the right directory and run. It outputs to a csv on your desktop.

ls | Select-Object Basename | Export-Csv C:\Users$env:username\Desktop\Output.csv

This will display files only:

ls | Where-Object {!$_.PSIsContainer -eq $True} | Select-Object Basename | Export-Csv C:\Users$env:username\Desktop\Output.csv

2
snaggletooth•

sweet, even better than mine

Get-ChildItem c:\ | % {$_.BaseName}
1
compywiz•

This should do the trick:

for %a in ("C:\your\folder\*") do @echo %~na

It turned up in a quick google - source: http://stackoverflow.com/questions/28157076/how-to-dir-without-showing-extension-batch

Edit: reddit formatting fk'd it up

1
brailOP•

I assume I am missing something, esp since I have never used cmd prompt for anything before other than finding my IP, but that didnt seem to actually do anything.

I replaced the "c your folder" part with my folders path, removed the quotes, and stuck it in cmd prompt, but nothing happened.

Dunno if theres an assumed step somewhere or what.

1
compywiz•

The quotes were literal and it looks like the reddit editor messed it up.

f:\>for %a in ("F:\Temp\test\*") do @echo %~na
0414142048
0414142049
2
brailOP•

Leaving the quotes in etc, still nothing seems to be happening.

If it helps, I am doing..

C:/users/brail>for %a in ("C:\Users\brail\Pictures\dnd\Images\H-Z\Misc_NPC\Coalition_Wizards\Wizard_1*") do @echo %~na

Sorry to keep bothering you, and thanks for your help

1
compywiz•
If the folder is called Wizard_1 you need a \* after the folder name. -- Wizard_1\*
2
FlosCarmeli•

you could install mobaxterm or cygwin and do it with ls -lh if you want

1
Nois3•

Why wouldn't you want to list the file extensions with the names?

1
brailOP•

Putting the file names into a spreadsheet, which will put them into a specific format to then produce a macro that I will use in an api on roll20.net, but the file extensions mess that up.

1
snaggletooth•

in powershell, Get-ChildItem c:\ | % {$_.BaseName}

1
tehjimmeh•

If you're just extracting a parameter, you can just pass that parameter's name to Foreach-Object rather than using a scriptblock:

ls | % BaseName
1