Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

FileName/Path to txt

Posted on 2006-11-26
11
Medium Priority
?
377 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 1500 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
Six Sigma Control Plans
Progress

718 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