Take the 2-minute tour ×

For example in windows explorer?

share|improve this question

closed as not a real question by karim79, Rob, Chris Ballance, Henrik Paul, John Saunders May 31 '09 at 21:07


Using any particular language/tool? –  Brian Agnew May 31 '09 at 16:14
In what sense? Do you want a context menu link to copy the file name? Or a script to do it, and print out the results? –  Kazar May 31 '09 at 16:14
Every time the contents of a shared folder on my computer is changed, I want an email to be sent to everyone with whom I have shared the folder. –  systemovich May 31 '09 at 18:26
add comment

7 Answers

up vote 11 down vote accepted

In the absence of any further information,

c:> cd directory
c:> dir > files.txt

to write a list of files to a text file (files.txt)

EDIT: dir /b to simply generate the bare file names

share|improve this answer
"dir /b >files-names.txt" <- '/b' stands for "bare listing" –  Ape-inago May 31 '09 at 17:00
Doh. Noted. Thanks –  Brian Agnew May 31 '09 at 17:02
Thanks, Brian. So this cannot be done in Windows, only in DOS? –  systemovich May 31 '09 at 18:22
Just open a command prompt in Windows (Start->Run... and launch 'cmd.exe') –  Brian Agnew May 31 '09 at 18:24
add comment

For just the file names:

c:\dir /b > files.txt
share|improve this answer
add comment

For a unix environment, cd mydirectory && ls > filelist.txt

share|improve this answer
note: ls is smart enough to know when it's being piped. so it doesn't give the normal information that it would if you ran it directly from the console. –  Ape-inago May 31 '09 at 17:01
add comment

I'm not sure if you care about distinguishing files and directories or not. The following will write the names of files in the current directory to listing.txt.


C:\> IF EXIST listing.txt ERASE listing.txt
C:\> FOR %I IN (*.*) DO (ECHO %~nxI) >>listing.txt

In any Bourne-based shell:

machine$ rm listing.txt
machine$ for f in *; do [ -f $f ] && echo "$f" >> listing.txt ; done


machine$ find . -type f -depth 1 -print > listing.txt
share|improve this answer
+1 for batch stuffs. –  Ape-inago May 31 '09 at 17:02
add comment

In python! It takes the path as an arguement.

import os
import sys

if __name__ == '__main__':
    path = sys.argv[1]

    dir = os.listdir(path)
    for fname in dir:
        print fname
share|improve this answer
add comment

If we're talking C# then the following will return the full path in an array of strings:

string[] files = Directory.GetFiles(directory);

To get the filenames:

foreach (string file in files)
share|improve this answer
add comment

To add some additional generic flavor, in a PHP one-liner, how about:

<?php file_put_contents("listing.txt", implode(PHP_EOL, glob('*')));
share|improve this answer
add comment
