1

I want to dump all the file names in a folder into without extension into a text file and additionally with them all being 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
  • 9
  • 3

2 Answers2

1

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
  • 53,069
  • 18
  • 138
  • 177
0

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
  • 34,184
  • 4
  • 22
  • 36