Z55
Z55

Reputation: 85

Getting directory names and writing them to a text file

How to please store the names of the directories to C:\maindir\ to file C:\export.txt ? Only directory, no files.

My directories

C:\maindir\dir1
C:\maindir\dir2
C:\maindir\dir3

export format file C:\export.txt

mytext dir1
mytext dir2
mytext dir3

Consult someone please ? Thank you

Upvotes: 0

Views: 29

Answers (2)

Alex K.
Alex K.

Reputation: 176016

You can;

for /f "delims=" %%a in ('dir /b /ad c:\maindir') do echo mytext %%a >> C:\temp\export.txt 

(Note on recent versions of windows you cannot write to the root of C:)

Upvotes: 1

ederpsampaio
ederpsampaio

Reputation: 82

You must get the list of the files in a variable (say FILELIST) and then perform a loop:

for i in $FILELIST; do
    if [ -d $i ]; then
        echo $i >> c:\export.txt
    fi
done

This must do what you need.

Upvotes: 0

Related Questions