Link to home
Start Free TrialLog in
Avatar of fmew
fmewFlag for Netherlands

asked on

FileName/Path to txt

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
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

something like this:
dir /A:-D >dir.txt
Avatar of gdepeute
gdepeute


  @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

ASKER CERTIFIED SOLUTION
Avatar of kumar_jac
kumar_jac
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or,

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

:-)
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
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).
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
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
Basically,  you should read the help of Dir command (Usage: dir /?) and use operator ">" into ouput to file instead of cout stream (Command display).
Avatar of fmew

ASKER

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