5

In Windows Command Prompt, I can use the dir command to output the names of all PNG files within a directory:

dir *.png /od /b > files.txt
file 1.png
file 2.png
...

However, the image files I am working with contain spaces in their filenames, and hence will not work with ImageMagick unless I surround their names with quotation marks, like so:

"file 1.png"
"file 2.png"
...

What is the best way to go about this?

Is there a command that lists filenames surrounded by quotes?

Or will I need to add them in after creating the txt file?

2
  • 1
    where /F ".:*.png"?
    – aschipfl
    Commented Aug 27, 2020 at 20:43
  • @aschipfl - Thanks, but I need the files in sequential order. This command will output: "file 1", "file 11", "file 12", etc. I used /od to order by date and get around this problem.
    – deanff
    Commented Aug 28, 2020 at 0:50

2 Answers 2

6

You can use FOR /F to run the DIR command and surround the output with quotes:

This is from the prompt

for /f "delims=" %A in ('dir /b /od *.png') do @echo "%A"

In a batch script, you would double the percent signs, so %A becomes %%A in both places.

0
4

A way using PowerShell:

(dir *.png | sort creationTime | % {"`"$($_.name)`""}) >>files.txt
  • Filter *.png using Get-ChildItem.
  • Sort them by CreationTime.
  • Add double quotes to their names using Foreach loop
  • Then write them to files.txt using operator.

You must log in to answer this question.

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