1

I want to dump all the file names in a folder without extension into a text file. They should be in one line separated by commas.

So in my folder I have

  • File1.bin
  • File2.bin
  • ....

With

(for %%a in (.\*.bin) do @echo %%~na,) >Dump.txt

I got

File1,
File2,

But what I want in the end is a text file with, so one long combined string.

File1,File2,...

I'm kinda stuck here and probably need something else than echo. Thanks for trying to help.

Daraan
  • 1,797
  • 13
  • 24

2 Answers2

2

Try like this:

@echo off

setlocal enableDelayedExpansion
for %%a in (.\*.txt) do (
    <nul set /p=%%~nxa,
)

check also the accepted answer here and the dbenham's one.

npocmaka
  • 55,367
  • 18
  • 148
  • 187
1

You could also leverage from a for this task:

@"%__APPDIR__%WindowsPowerShell\v1.0\powershell.exe" -NoProfile -Command "( Get-Item -Path '.\*' -Filter '*.bin' | Where-Object { -Not $_.PSIsContainer } | Select-Object -ExpandProperty BaseName ) -Join ',' | Out-File -FilePath '.\dump.txt'"

This could probably be shortened, if necessary, to:

@PowerShell -NoP "(GI .\*.bin|?{!$_.PSIsContainer}|Select -Exp BaseName) -Join ','>.\dump.txt"
Compo
  • 36,585
  • 5
  • 27
  • 39