For example in a folder named sample there are 3 images namely img1.jpg & img2.jpg & img3.jpg
I want to copy all the paths of all images to a .txt
file
content of .txt will be
C:/sample/img1.jpg
C:/sample/img2.jpg
C:/sample/img3.jpg
Run this in your directory that you want to tree. It extends the path name.
> "dirs.txt" (for %A in (*) do echo %~fA)
Edited in regards to aschipfl's comments
I would start here: http://ss64.com/nt/for_d.html . This link shows how to iterate through files. in the example you can use this and modify for output to a file. The second one is a starting point for output.
FOR /D /r %G in ("User*") DO Echo We found %G
FOR /D /r %G in ("User*") DO Echo "We found %G" >> C:\test.txt
You can use the dir command with recursion and bare format option like so
dir /s /b *.jpg > files.txt
Reference:
Clayton Wahlstrom's answer is a good start, but it can be improved:
>>
operator is placed in the body of the for
loop; however, redirecting all data once would improve the overall performance; >>
redirection operator; dirs.txt
does not yet exist or is empty initially, because the >>
redirection appends data if applicable; for
loop variables, to be able to distinguish them from the ~
modifiers; To overcome all these issues, just put the entire for
loop into parentheses ()
and do the redirection >
once only, like this:
> "dirs.txt" (for %A in (*) do echo %~fA)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.