edinvnode
edinvnode

Reputation: 3537

Batch command(s) to show all files in folders

I am using this method to save file names in folder into a txt file.

Let's say I have file1.txt and file2.txt in C:\somefolder\somefolder1\ and file3.txt and file4.txt in C:\somefolder\somefolder2\

cd C:\somefolder\somefolder1\
dir /b /o *.* >> paths.txt
cd C:\somefolder\somefolder2\
dir /b /o *.* >> paths.txt

And I get a result like this.

file1.txt
file2.txt
paths.txt

and

file3.txt
file4.txt
paths.txt

I need a code that would save files in 1 file with their paths. So like this.

C:\somefolder\somefolder1\file1.txt
C:\somefolder\somefolder1\file2.txt
C:\somefolder\somefolder2\file3.txt
C:\somefolder\somefolder2\file4.txt

And I need a way to specify where that file would be. Like for example the location of such a file would be. C:\somefolder\paths.txt

Upvotes: 0

Views: 105

Answers (1)

foxidrive
foxidrive

Reputation: 41224

Try this:

@echo off
for %%a in (
"C:\somefolder\somefolder1"
"C:\somefolder\somefolder2"
) do dir /b /s /a-d >>"C:\somefolder\paths.txt"

Upvotes: 1

Related Questions