Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I output the list of files in a directory in double-quotes?

Tags:

windows

cmd

How to enclose each line resulted from command line dir/b /s /c *.txt inside quotations

dir/b /s /c *.txt

The command displays all the txt file available in the directory. I need the path of each file inside double quotes

like image 602
Hanumanth Avatar asked Nov 22 '25 18:11

Hanumanth


1 Answers

You can use the for command, for example, this outputs all the requested files into a file named x.x:

(for /f "delims=" %f in ('dir /b /s /c *.txt') do @echo "%f") > x.x

Note that if you use this in a batch file (ie. not directly from the command prompt), you have to escape the % char as %%, ie:

(for /f "delims=" %%f in ('dir /b /s /c *.txt') do @echo "%%f") > x.x

Also, if you have PowerShell on the computer (server Windows do from version 2k3 or so, I'm not sure; you can install it of course), that's an even more powerful command-line tool - it basically gives you a fully fledged .NET language to do even complex administration tasks. However, I tend to use simple tools for simple tasks, and this is still a simple task :)

like image 75
Luaan Avatar answered Nov 24 '25 07:11

Luaan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!