For example in windows explorer?
+8
A:
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
Brian Agnew
2009-05-31 16:16:38
"dir /b >files-names.txt" <- '/b' stands for "bare listing"
Ape-inago
2009-05-31 17:00:48
Doh. Noted. Thanks
Brian Agnew
2009-05-31 17:02:18
Thanks, Brian. So this cannot be done in Windows, only in DOS?
Geoffrey Van Wyk
2009-05-31 18:22:25
Just open a command prompt in Windows (Start->Run... and launch 'cmd.exe')
Brian Agnew
2009-05-31 18:24:44
+1
A:
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)
{
Console.WriteLine(Path.GetFileName(file));
}
ChrisF
2009-05-31 16:21:02
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
2009-05-31 17:01:36
A:
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
Cdsboy
2009-05-31 16:27:46
A:
To add some additional generic flavor, in a PHP one-liner, how about:
<?php file_put_contents("listing.txt", implode(PHP_EOL, glob('*')));
Henrik Paul
2009-05-31 16:27:51
+2
A:
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
.
In DOS:
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
or:
machine$ find . -type f -depth 1 -print > listing.txt
D.Shawley
2009-05-31 16:46:01