Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

FileName/Path to txt

Posted on 2006-11-26
11
370 Views
Last Modified: 2010-04-16
Hi There,

I want to send all filenames and filepaths in a dir to a txt file. Can this be done with a dos batch cmd?

Erik
0
Comment
Question by:fmew
11 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18017618
something like this:
dir /A:-D >dir.txt
0
 
LVL 1

Expert Comment

by:gdepeute
ID: 18017641

  @del dirs.txt >NUL 2>&1
  for /R %d IN (*) DO @echo %d >> dirs.txt
or
  @del dirs.txt >NUL 2>&1
  for /R C:\temp %d IN (*) DO @echo %d >> dirs
  if you want to specify a directory (C:\temp in this case)

-- Geert

0
 
LVL 5

Accepted Solution

by:
kumar_jac earned 500 total points
ID: 18018790

Hi,
        If  you want with full path please You have to use /S switch it reutrns result from subdirectry too.

 please use

           DIR/B/S > FilenameList.txt



regards,
Krishna kumar.M
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 67

Expert Comment

by:sirbounty
ID: 18019236
Or,

for /r c:\ %a in (*.*) do echo %a >> c:\Output.txt

:-)
0
 
LVL 4

Expert Comment

by:chhokra_expert
ID: 18021951
dir /a/s/b > list.txt

the search starts in current dir

/a = all files (including those with sys attrib or other wise hidden)
/s = sub directory search (remove this if you don't want a recursive search through all sub directories)
/b = bare file name (will not print size or modification time)
> = redirect output to file. if you want to append to the file use >> instead.

typically when generating list of files, you may want to sort the results alphabetically. the following will do that for you

dir /a/s/b | sort > list.txt

hth,
kage
0
 
LVL 3

Expert Comment

by:taycuong76
ID: 18035144
Action.bat

Dir YOURDIR /a > RESULT.txt

in which:
- YOURDIR: dir to do with (should add the full path).
- RESULT.txt: file that hold the output (should add the full path).
0
 
LVL 3

Expert Comment

by:taycuong76
ID: 18035189
For a Flexible method, you can output any dir to a txt file:
Create a file named Xdir.bat with content:

Dir %1 /a > RESULT.txt

(in which: %1 is placeholder for dir name to do with. You could replace it with any dir name when run)

Try it, for example::

C:\> Xdir c:\DOS
C:\> Xdir d:\setup
 ...

It will output the filenames and filepaths in given dir to RESULT.txt
0
 
LVL 3

Expert Comment

by:taycuong76
ID: 18035207
For a more Flexible method, you can create a file named Xdir.bat with content:

Dir %1 /a  >  %1.txt

Then if you run the batch file with dirname as command line's argument, it will output the filenames and filepaths in given dir to a text file named after dirname.

C:\> Xdir c:\DOS  ---> DOS.txt
C:\> Xdir D:\SETUP  ---> SETUP.txt
C:\> Xdir E:\XXX  ---> XXX.txt
0
 

Expert Comment

by:leroopsin
ID: 18058516
Basically,  you should read the help of Dir command (Usage: dir /?) and use operator ">" into ouput to file instead of cout stream (Command display).
0
 

Author Comment

by:fmew
ID: 18326306
I thought this question needed a complex answer (without thinking about a solution for myself).
This is not so.
Krishna Kumar's answer solves my question, thats why I accept your answer.
Probably with to much points.


Erik
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
This is about my first experience with programming Arduino.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question