Solved

FileName/Path to txt

Posted on 2006-11-26
11
372 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
[X]
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
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
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…

734 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