I want to use the Windows command line to list files with path.
For example:
~\folder1
\1.jpg
\2.jpg
~\folder2
\01.jpg
\02.jpg
I want the output to be similar to the relative paths rather than the full path though:
.\folder1\1.jpg
.\foler1\2.jpg
When I use DIR /S /B *.jpg > list.txt
that lists the full path like C:\download\folder\folder1\1.jpg
, I only need it to list the relative path like .\folder1\1.jpg
…
Using the Linux Command Line of find ./ -iname *.jpg > list.txt
, gives me the expected result but I need a solution that'll work like this with Windows.
Best Answer
Variable Clarification (below)
FOR %X IN ("folder1","Folder2")
orSET Folders=("Folder1","Folder2","Folder3","Folder4")
you will put your"Folder1"
,"Folder2"
, and so on just like that with the double quotes and commas for each folder name you want to look for and list the./Foldername/file.jpg
to the file you are appending the echo'd output.CD /D C:\Path
to the parent directory where the subfolders where the.JPG
files exist as that logic is implicit assuming you're in the parent directory to find those child subfolders and the filetypes/extensions they contain..JPG
files exist in theSET ParentDir=
value and everything should work otherwise as expected.SET
should be self explanatory I assume as those are named pretty close to what they mean but let me know if you need further clarification otherwise.Command Line Copy Example
Set Variables Command Line Copy Example
(Use the below to set your folder names and file extensions for the
DIR
command. Also plug in the parent directory full path where the subfolders you want to append in that format to the text file is located.)Batch Script Example with Setting Variables
Further Reading and Resources