Walk a directory/Non-recursively: Difference between revisions
m
syntax highlighting fixup automation
(Added Hare) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 19:
{{trans|Python}}
<
I filename.ends_with(‘.mp3’)
print(filename)</
=={{header|68000 Assembly}}==
Non-recursive directory walk in Motorola 68000 assembly language under AmigaOs 2.04+ by Thorham. Uses regular Amiga dos pattern matching.
<
; Non-recursive directory walk for Motorola 68000 under AmigaOs 2.04+ by Thorham
;
Line 203:
patternParsed
dcb.b sizeof_patternString*2+2</
=={{header|8080 Assembly}}==
Line 211:
the filename, the extension, and an optional drive letter.
<syntaxhighlight lang="text">exit: equ 0 ; CP/M syscall to exit
puts: equ 9 ; CP/M syscall to print a string
sfirst: equ 17 ; 'Find First' CP/M syscall
Line 254:
ret
emsg: db 'Not Found$'
fname: db 'XXXXXXXX.XXX',13,10,'$' ; Filename placeholder</
{{out}}
Line 285:
=={{header|8th}}==
<
"*.c" f:glob \ puts an array of strings with the file names on the top of the stack
</syntaxhighlight>
=={{header|Action!}}==
The attached result has been obtained under DOS 2.5.
<
BYTE i,len
Line 337:
Dir("H1:?????.ACT")
Dir("H1:??F*.*")
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Walk_a_directory_non-recursively.png Screenshot from Atari 8-bit computer]
Line 366:
=={{header|Ada}}==
{{works with|GCC|4.12}}
<
with Ada.Text_IO; use Ada.Text_IO;
Line 384:
End_Search (Search);
end Walk_Directory;</
=={{header|ALGOL 68}}==
Line 390:
{{works with|ALGOL 68G|Any - tested with release mk15-0.8b.fc9.i386 - uses non-standard library routines ''get directory'' and'' grep in string''.}}
<!-- {{does not work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release 1.8.8d.fc9.i386 - ''get directory'' and'' grep in string'' not available in any library ... yet}} -->
<
[]STRING directory = get directory(".");
Line 398:
print((file, new line))
FI
OD</
{{out|Sample output}}
<pre>
Line 414:
AppleScript itself has limited built-in file system access. Typically, the Mac OS Finder is used to gather such information.
To list all file/folders in the root directory:
<
--> EXAMPLE RESULT: {"Applications", "Developer", "Library", "System", "Users"}</
To list all pdf files in user's home directory:
<
--> EXAMPLE RESULT: {"About Stacks.pdf", "Test.pdf"}</
The key clause is the <code>whose</code> modifier keyword. The Finder can interpret many variations, including such terms as <code>whose name begins with</code>, <code>whose name contains</code>, etc. As well as boolean combinations:
<
--> RETURNS: {"Test.pdf"}</
The Finder also supports the <code>entire contents</code> modifier keyword, which effectively performs a recursive directory scan without recursion.
<
----
Nowadays, it's more usual to use macOS's System Events application for this kind of task as it's very much faster than the Finder, especially with 'whose' filters. However, its results, unlike the Finder's, aren't sorted by the items' names and it includes results for hidden items too if these match the criteria.
<
--> EXAMPLE RESULT: {"ShellScripting.pdf", "RFC 4180 (CSV spec).pdf", "About Stacks.pdf", "AppleScriptLanguageGuide.pdf", "robinson_jeffers_2004_9.pdf", "DiskWarrior Manual.pdf", "RFC 2445 (iCalendar spec).pdf", "Artistic Orchestration.pdf"}</
Intermediate in speed between the Finder and System Events are shell scripts, which are handy if you're more comfortable with shell scripts than with AppleScript.
<
-- By default, "ls" returns file names sorted by character code, so save the sorting until the end and do it case-insensitively.
set shellCommandText to "ls -f " & quoted form of docsFolderPath & " | grep -i '\\.pdf$' | sort -f"
return paragraphs of (do shell script shellCommandText)
--> EXAMPLE RESULT: {"About Stacks.pdf", "AppleScriptLanguageGuide.pdf", "Artistic Orchestration.pdf", "DiskWarrior Manual.pdf", "RFC 2445 (iCalendar spec).pdf", "RFC 4180 (CSV spec).pdf", "robinson_jeffers_2004_9.pdf", "ShellScripting.pdf"}</
Best of all for speed and sorting, although requiring somewhat more code, are the Foundation methods available through AppleScriptObjC.
<
use framework "Foundation"
use scripting additions
Line 458:
-- Return the result as an AppleScript list of text.
return pdfNames as list
--> EXAMPLE RESULT: {"About Stacks.pdf", "AppleScriptLanguageGuide.pdf", "Artistic Orchestration.pdf", "DiskWarrior Manual.pdf", "RFC 2445 (iCalendar spec).pdf", "RFC 4180 (CSV spec).pdf", "robinson_jeffers_2004_9.pdf", "ShellScripting.pdf"}</
=={{header|Arturo}}==
<
print list "."
Line 474:
; just select the files that contain "test"
select list "some/path"
=> [in? "test"]</
=={{header|AutoHotkey}}==
Display all INI files in Windows directory.
<
out .= A_LoopFileName "`n"
MsgBox,% out</
=={{header|BaCon}}==
This code will print all files in the current directory ".", separated by a newline symbol:
<
=={{header|BASIC}}==
Line 491:
DOS wildcards are rather underpowered when compared to... well... anything else.
{{works with|FreeBASIC}}
<
show "*.*"
Line 502:
f = DIR$
LOOP
END SUB</
=={{header|BASIC256}}==
<
end
Line 514:
f$ = dir
end while
end subroutine</
=={{header|Batch File}}==
A simple command that displays all EXE files in System32 directory non-recursively.
<
The same command inside FOR loop:
*Inside a Batch File:
<
*Command-line:
<
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<
pattern$ = "*.ini"
PROClistdir(directory$ + pattern$)
Line 543:
SYS "FindClose", sh%
ENDIF
ENDPROC</
=={{header|C}}==
Line 549:
{{works with|POSIX|.1-2001}}
In this example, the pattern is a [[POSIX]] extended regular expression.
<
#include <dirent.h>
#include <regex.h>
Line 582:
walker(".", ".\\.c$");
return 0;
}</
=={{header|C sharp|C#}}==
<
using System.IO;
Line 600:
}
}
</syntaxhighlight>
=={{header|C++}}==
{{libheader|boost|1.50.0}}
<
#include "boost/regex.hpp"
#include <iostream>
Line 626:
}
}
}</
{{libheader|std|C++17}}
<
#include <filesystem>
#include <iostream>
Line 642:
std::cout << file.path().filename().string() << std::endl;
}
}</
=={{header|Clojure}}==
Using Java 8's [https://docs.oracle.com/javase/8/docs/api/java/nio/file/FileSystem.html#getPathMatcher-java.lang.String- PathMatcher] patterns.
<
(defn match-files [f pattern]
Line 655:
(let [directory (clojure.java.io/file dir)]
(map #(.getPath %) (filter #(match-files % pattern) (.listFiles directory)))))
</syntaxhighlight>
=={{header|ColdFusion}}==
This example display all files and directories directly under '''C:\temp''' that end with ''.html''
<
<cfoutput query="dirListing">
#dirListing.name# (#dirListing.type#)<br>
</cfoutput></
=={{header|Common Lisp}}==
<
(directory (merge-pathnames pattern directory)))</
Uses the filename pattern syntax provided by the CL implementation.
=={{header|D}}==
<
import std.stdio, std.file;
dirEntries(".", "*.*", SpanMode.shallow).writeln;
}</
=={{header|DCL}}==
<pre>* matches any number of characters
& matches exactly any one character</pre>
<syntaxhighlight lang="text">$ loop:
$ f = f$search( p1 )
$ if f .eqs. "" then $ exit
$ write sys$output f
$ goto loop</
{{out}}
<pre>$ @walk_a_directory *.*
Line 705:
{{libheader| System.IOUtils}}
<syntaxhighlight lang="delphi">
program Walk_a_directory;
Line 730:
end.
</syntaxhighlight>
{{out}}
Line 738:
=={{header|E}}==
<
for name => file ? (name =~ rx`.*$pattern.*`) in directory {
println(name)
}
}</
Example:
<
.bash_history
.bash_profile
.bash_profile~</
=={{header|Elena}}==
ELENA 4.0:
<
import system'routines;
import extensions'routines;
Line 760:
dir.getFiles("a.*").forEach:printingLn;
}</
=={{header|Elixir}}==
<
IO.inspect File.ls!
dir = "/users/public"
IO.inspect File.ls!(dir)</
{{out}}
Line 780:
directory, optionally restricted to those matching a regexp.
<
nil ;; just the filenames, not full paths
"\\.c\\'" ;; regexp
t) ;; don't sort the filenames
;;=> ("foo.c" "bar.c" ...)</
=={{header|Erlang}}==
Line 799:
=={{header|Euphoria}}==
<
procedure show(sequence pattern)
Line 810:
end procedure
show("*.*")</
=={{header|F_Sharp|F#}}==
<
|> Array.iter (printfn "%s")</
=={{header|Factor}}==
Using unix globs. Also see the "directory." in basis/tools/files.factor.
<
IN: walk-directory-non-recursively
: print-files ( path pattern -- )
[ directory-files ] [ <glob> ] bi* [ matches? ] curry filter
[ print ] each ;</
Ex:
( scratchpad ) "." "*.txt" print-files
Line 831:
{{works with|gforth|0.6.2}}
Gforth's directory walking functions are tied to the POSIX ''dirent'' functions, used by the C langauge entry above. Forth doesn't have regex support, so a simple filter function is used instead.
<
: ls-all 2drop true ;
: ls-visible drop c@ [char] . <> ;
Line 855:
' c-file? is ls-filter
s" ." ls</
=={{header|FreeBASIC}}==
{{trans|BASIC}}
<
Sub show (pattern As String)
Dim As String f = Dir$(pattern)
Line 870:
show "*.*"
Sleep
</syntaxhighlight>
=={{header|Frink}}==
This prints the names of all of the files in the current directory that end with <CODE>.frink</CODE> using a regular expression.
<
println[f.getName[]]</
{{out}}
Line 889:
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/?gist=c5fde952fecd1d7052101b1e2287f2ff Click this link to run this code]'''
<
Dim sTemp As String
Line 896:
Next
End</
Output:
<pre>
Line 910:
=={{header|Go}}==
<
import (
Line 919:
func main() {
fmt.Println(filepath.Glob("*.go"))
}</
=={{header|Groovy}}==
<
new File('.').eachFileMatch(~/.*\.txt/) {
println it
Line 930:
new File('/foo/bar').eachFileMatch(~/.*\.txt/) {
println it
}</
=={{header|Hare}}==
<
use glob;
Line 951:
fmt::printfln("{}", s)!;
};
};</
=={{header|Haskell}}==
{{works with|GHC|GHCi|6.6}}
In this example, the pattern is a POSIX extended regular expression.
<
import Text.Regex
import Data.Maybe
Line 965:
mapM_ putStrLn $ filter (isJust.(matchRegex $ mkRegex pattern)) filenames
main = walk "." ".\\.hs$"</
=={{header|HicEst}}==
More on [http://www.HicEst.com/SYSTEM.htm SYSTEM], [http://www.HicEst.com/OPEN.htm OPEN], [http://www.HicEst.com/indexfnc.htm INDEX]
<
SYSTEM(DIR='*.*', FIle=dirtxt) ! "file names", length, attrib, Created, LastWrite, LastAccess
Line 978:
! write file names with extensions "txt", or "hic", or "jpg" (case insensitive) using RegEx option =128:
IF( INDEX(filename, "\.txt|\.hic|\.jpg", 128) ) WRITE() filename
ENDDO</
=={{header|Icon}} and {{header|Unicon}}==
This uses Unicon extensions for ''stat'' and to read directories. Icon can uses ''system'' to accomplish the same objective.
<
every write(getdirs(".","icn")) # writes out all directories from the current directory down
end
Line 995:
close(d)
}
end</
=={{header|IDL}}==
<
if cc gt 0 then print,f</
(IDL is an array language - very few things are ever done in 'loops'.)
=={{header|J}}==
<
0 dir '*.png'
0 dir '/mydir/*.txt'</
The verb <tt>dir</tt> supports a number of reporting options determined by its left argument. A left argument of <tt>0</tt> reports just the file names.
=={{header|Java}}==
<
String[] contents = dir.list();
for (String file : contents)
if (file.endsWith(".mp3"))
System.out.println(file);</
=={{header|JavaScript}}==
{{works with|JScript}}
<
var dir = fso.GetFolder('test_folder');
Line 1,039:
}
walkDirectory(dir, '\\.txt$');</
=={{header|Julia}}==
{{works with|Julia|0.6}}
<
if endswith(filename, ".mp3")
print(filename)
end
end</
=={{header|Kotlin}}==
<
import java.io.File
Line 1,065:
val files = walkDirectory("/usr/include", r)
for (file in files) println(file)
}</
Sample output (Ubuntu v14.04):
{{out}}
Line 1,080:
=={{header|Lasso}}==
<
dir('.') -> foreach => {#1 >> 'string' ? #matchingfilenames -> insert(#1)}
#matchingfilenames</
-> array(mystrings.html, a_string_file.txt)
=={{header|Lingo}}==
<
on printFiles (dir, fileType)
i = 1
Line 1,099:
if fn.char[fn.length-sub..fn.length]=fileType then put fn
end repeat
end</
=={{header|LiveCode}}==
<
put the files into docfiles
filter docfiles with "*.txt"
put docfiles</
=={{header|Lua}}==
Lua itself is extremely spartanic as it is meant for embedding. Reading out a directory is not something that a minimal standard C library can do, and so minimal Lua without native extension libraries can't do it either. But lfs (LuaFileSystem) is about as standard an extension as it gets, so we use that.
<
directorypath = "." -- current working directory
for filename in lfs.dir(directorypath) do
Line 1,115:
print(filename)
end
end</
Although Lua is spartanic, it still provides functions such as os.execute([command]) and io.popen(prog [, mode]). Below an example for Windows users having io.popen at their disposal. Mind you, it may pop-up a command window.
<
-- Note that io.popen is not available on all platforms
local function getOutput(prog)
Line 1,147:
print(filename)
end
end</
=={{header|M2000 Interpreter}}==
Line 1,155:
There is a second optional parameter which examine all files founded from first filter for included letters. We can add using | as seperator, a list of strings included in same line. Files examine all files, opened one by one, using an automatic way to find what kind of text file is, an Ansi, a Utf8, a Utf-16LE, or a Utf-16BE. Also automatic find the line breaks. All files converted at open as utf-16LE and then searched. For Ansi files, Locale used to make the right conversion.
<syntaxhighlight lang="m2000 interpreter">
Module Show_Files_Standard {
\\ we get more (include hidden too)
Line 1,176:
}
Show_Files_Standard
</syntaxhighlight>
Like VbScript using external help, from a COM object.
Line 1,186:
Stack New {} make a block of a fresh stack of values, and at the exit attach the old stack (which for this block detached from execute object at the begin of block).
<syntaxhighlight lang="m2000 interpreter">
Module Show_Files {
Function get_files$ (folder_path$) {
Line 1,215:
}
Show_Files
</syntaxhighlight>
=={{header|MACRO-10}}==
<syntaxhighlight lang="macro-10">
TITLE DIRWLK - Directory Walker
SUBTTL PDP-10 Assembly Language (MACRO-10 @ TOPS-20). KJX 2022.
Line 1,261:
END GO
</syntaxhighlight>
=={{header|Mathematica}}/{{header|Wolfram Language}}==
Line 1,271:
:<code>FileNames[forms,dirs,n]</code> includes files that are in subdirectories up to n levels down.
Examples (find all files in current directory, find all png files in root directory):
<
FileNames["*.png", $RootDirectory]</
the result can be printed with Print /@ FileNames[....].
=={{header|MAXScript}}==
<
=={{header|Nanoquery}}==
<
for fname in new(File).listDir("/foo/bar")
Line 1,285:
println filename
end
end</
=={{header|Nemerle}}==
<
using System.IO;
Line 1,300:
foreach (file in files) WriteLine(file);
}
}</
=={{header|NetRexx}}==
<
options replace format comments java crossref symbols nobinary
Line 1,337:
return
</syntaxhighlight>
{{out}}
<pre>
Line 1,354:
Here is an example with <code>walkFiles</code> and a pattern:
<
for file in walkFiles "/foo/bar/*.mp3":
echo file</
=={{header|Objeck}}==
<
bundle Default {
Line 1,373:
}
}
}</
=={{header|Objective-C}}==
<
// Pre-OS X 10.5
Line 1,385:
for (NSString *file in contents)
if ([[file pathExtension] isEqualToString:@"mp3"])
NSLog(@"%@", file);</
=={{header|OCaml}}==
<
let contents = Array.to_list (Sys.readdir ".") in
let select pat str = Str.string_match (Str.regexp pat) str 0 in
List.filter (select ".*\\.jpg") contents</
=={{header|Oz}}==
<
[Path] = {Module.link ['x-oz://system/os/Path.ozf']}
[Regex] = {Module.link ['x-oz://contrib/regex']}
Line 1,402:
MatchingFiles = {Filter Files fun {$ File} {Regex.search Pattern File} \= false end}
in
{ForAll MatchingFiles System.showInfo}</
=={{header|Pascal}}==
{{works with|Free Pascal}}
<
program Walk;
Line 1,436:
end;
FindClose(Res);
end.</
=={{header|Perl}}==
<
opendir my $dh, '/home/foo/bar';
say for grep { /php$/ } readdir $dh;
closedir $dh;</
Or using globbing, with the <code><></code> operator,
<
Or the same with the builtin <code>glob()</code> function,
<
The <code>glob()</code> function takes any expression for its pattern, whereas <code><></code> is only for a literal.
<
my @filenames = glob($pattern);</
=={{header|Phix}}==
{{libheader|Phix/basics}}
The dir function accepts a DOS pattern, with some minor variations (eg "*" gets all files with no extension).
<!--<
<span style="color: #7060A8;">puts</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">columnize</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">dir</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"*.txt"</span><span style="color: #0000FF;">))[</span><span style="color: #000000;">D_NAME</span><span style="color: #0000FF;">],</span><span style="color: #008000;">"\n"</span><span style="color: #0000FF;">))</span>
<!--</
{{out}}
<pre>
Line 1,469:
=={{header|PHP}}==
{{works with|PHP|5.2.0}}
<
$dh = opendir('c:/foo/bar'); // Or '/home/foo/bar' for Linux
while (false !== ($file = readdir($dh)))
Line 1,481:
}
}
closedir($dh);</
Or:
<
foreach (scandir('/home/foo/bar') as $file)
{
Line 1,493:
}
}
}</
{{works with|PHP|<nowiki>4 >= 4.3.0 or 5</nowiki>}}
<
echo "$file\n";
}</
=={{header|PicoLisp}}==
<
(when (match '`(chop "s@.c") (chop F)) # Matches 's*.c'?
(println F) ) ) # Yes: Print it</
{{out}}
<pre>"start.c"
Line 1,511:
=={{header|Pike}}==
<
foreach(files, string file)
write(file + "\n");</
=={{header|Pop11}}==
Built-in procedure sys_file_match searches directories (or directory trees) using shell-like patterns:
<
;;; create path repeater
sys_file_match('*.p', '', false, 0) -> repp;
Line 1,524:
;;; print the file
printf(fil, '%s\n');
endwhile;</
=={{header|PowerShell}}==
Since PowerShell is also a shell it should come as no surprise that this task is very simple. Listing the names of all text files, or the names of all files, starting with "f":
<
Get-ChildItem f* -Name</
The <code>-Name</code> parameter tells the <code>Get-ChildItem</code> to return only the file names as string, otherwise a complete <code>FileInfo</code> or <code>DirectoryInfo</code> object would be returned, containing much more information than only the file name.
More complex matching can be accomplished by filtering the complete list of files using the <code>Where-Object</code> cmdlet. The following will output all file names that contain at least one vowel:
<
=={{header|PureBasic}}==
The match is made using DOS wildcards. It could easily be modified to match based on a regular expression if desired (i.e. using the PCRE library).
<
Protected directoryID
Line 1,555:
Input()
CloseConsole()
EndIf</
=={{header|Python}}==
The [http://python.org/doc/lib/module-glob.html glob] library included with Python lists files matching shell-like patterns:
<
for filename in glob.glob('/foo/bar/*.mp3'):
print(filename)</
Or manually:
<
for filename in os.listdir('/foo/bar'):
if filename.endswith('.mp3'):
print(filename)</
=={{header|R}}==
<
=={{header|Racket}}==
<syntaxhighlight lang="racket">
-> (for ([f (directory-list "/tmp")] #:when (regexp-match? "\\.rkt$" f))
(displayln f))
... *.rkt files ...
</syntaxhighlight>
=={{header|Raku}}==
(formerly Perl 6)
The <code>dir</code> function takes the directory to traverse, and optionally a named parameter <code>test</code>, which is [https://docs.raku.org/routine/$TILDE$TILDE smart-matched] against the basename of each file (so for example we can use a regex):
<syntaxhighlight lang="raku"
=={{header|Rascal}}==
<
public void Walk(loc a, str pattern){
for (entry <- listEntries(a))
endsWith(entry, pattern) ? println(entry);
}</
=={{header|Raven}}==
<
item m/\.txt$/ if "%(item)s\n" print</
=={{header|REXX}}==
{{works with|Regina}}
The following program was tested in a DOS window under Windows/XP and should work for all Microsoft Windows.
<
parse arg xdir; if xdir='' then xdir='\' /*Any DIR? Use default.*/
@.=0 /*default in case ADDRESS fails. */
Line 1,614:
do j=1 for #; say @.j; end /*show files that met criteria. */
exit @.0+rc /*stick a fork in it, we're done.*/</
=={{header|Ring}}==
<
###---------------------------------------
Line 1,708:
###===============================================
</syntaxhighlight>
OUTPUT:
Line 1,771:
=={{header|Ruby}}==
<
Dir.glob('*') { |file| puts file }
Line 1,782:
puts file if file =~ pattern
end
end</
=={{header|Run BASIC}}==
<
if #g HASANSWER() then
Line 1,796:
next
end if
wait</
FILE ACCESSOR methods
Line 1,824:
=={{header|Rust}}==
<
extern crate regex;
extern crate rustc_serialize;
Line 1,859:
}
}
}</
=={{header|Scala}}==
<
val dir = new File("/foo/bar").list()
dir.filter(file => file.endsWith(".mp3")).foreach(println)</
=={{header|Seed7}}==
<
include "osfiles.s7i";
Line 1,880:
end if;
end for;
end func;</
=={{header|Sidef}}==
<
{{out}}
<pre>
Line 1,890:
</pre>
<
path.open(\var dir_h) || return nil
dir_h.entries.each { |entry|
Line 1,905:
say file;
}
)</
{{out}}
<pre>
Line 1,913:
=={{header|Smalltalk}}==
<
allFilesMatching: '*.st' do: [ :f | (f name) displayNl ]</
=={{header|Standard ML}}==
<
let
fun loop strm =
Line 1,926:
in
loop strm before OS.FileSys.closeDir strm
end</
List all "hidden" files (starting with a dot in Unix) in the current directory:
<
=={{header|Tcl}}==
For the current directory:
<
puts $filename
}</
For an arbitrary directory:
<
foreach filename [glob -directory $dir *.txt] {
puts $filename
### Or, if you only want the local filename part...
# puts [file tail $filename]
}</
=={{header|Toka}}==
As with the C example, this uses a a POSIX extended regular expression as the pattern. The '''dir.listByPattern''' function used here was introduced in library revision 1.3.
<
" ." " .\\.txt$" dir.listByPattern</
=={{header|TUSCRIPT}}==
<
files=FILE_NAMES (+,-std-)
fileswtxt= FILTER_INDEX (files,":*.txt:",-)
txtfiles= SELECT (files,#fileswtxt)</
{{out}}
<pre>
Line 1,964:
==== Using <code>glob</code> ====
<
{{out}}
<
"/etc/ca-certificates.conf" "/etc/colord.conf" "/etc/ddclient.conf"
"/etc/debconf.conf" "/etc/deluser.conf" "/etc/dnsmasq.conf" "/etc/ffserver.conf"
Line 1,978:
"/etc/pnm2ppa.conf" "/etc/popularity-contest.conf" "/etc/resolv.conf"
"/etc/rsyslog.conf" "/etc/sensors3.conf" "/etc/sysctl.conf" "/etc/ucf.conf"
"/etc/updatedb.conf" "/etc/usb_modeswitch.conf" "/etc/wodim.conf")</
==== Using <code>open-directory</code> and <code>get-lines</code> ====
<
{{out}}
<
"debconf.conf" "apg.conf" "adduser.conf" "mke2fs.conf" "colord.conf"
"kerneloops.conf" "fuse.conf" "hdparm.conf" "irssi.conf" "host.conf"
Line 1,994:
"knockd.conf" "ntp.conf" "sensors3.conf" "resolv.conf" "blkid.conf"
"lftp.conf" "ca-certificates.conf" "usb_modeswitch.conf" "logrotate.conf"
"rsyslog.conf" "pnm2ppa.conf")</
=={{header|UNIX Shell}}==
<
(cd mydir && ls -d *.c) # *.c files in mydir</
<code>*.c</code> is a ''file name pattern'', also known as a ''glob pattern''. The shell expands each pattern to a sorted list of matching files. Details are in your shell's manual.
Line 2,005:
=={{header|UnixPipes}}==
Here using grep for regexp.
<
=={{header|VBScript}}==
<syntaxhighlight lang="vb">
Sub show_files(folder_path,pattern)
Set objfso = CreateObject("Scripting.FileSystemObject")
Line 2,019:
Call show_files("C:\Windows",".exe")
</syntaxhighlight>
=={{header|Visual Basic .NET}}==
{{works with|Visual Basic .NET|9.0+}}
<
For Each file In IO.Directory.GetFiles("\temp", "*.txt")
Console.WriteLine(file)
Line 2,036:
For Each file In IO.Directory.GetFiles("\temp").Where(Function(f) f Like "*.txt")
Console.WriteLine(file)
Next</
=={{header|Wren}}==
{{libheader|Wren-pattern}}
<
import "/pattern" for Pattern
Line 2,051:
// get all C header files beginning with 'a' or 'b'
var p = Pattern.new("[a|b]+0^..h", Pattern.whole)
for (f in walk.call("/usr/include", p)) System.print(f)</
{{out}}
Line 2,068:
=={{header|zkl}}==
Unix glob, with wildcarding and options on file type, case folding and a few others.
<
=={{header|Zsh}}==
Zsh has powerful filename generation features, which can filter by file names, permissions, size, type, etc.
<
{{omit from|AWK|Use a shell command: system("ls *.awk")}}
|