Solved

FileName/Path to txt

Posted on 2006-11-26
11
369 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 142

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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This is about my first experience with programming Arduino.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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…

776 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