Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
5
Task/Walk-a-directory-Recursively/00-META.yaml
Normal file
5
Task/Walk-a-directory-Recursively/00-META.yaml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
category:
|
||||
- Recursion
|
||||
from: http://rosettacode.org/wiki/Walk_a_directory/Recursively
|
||||
note: File System Operations
|
||||
14
Task/Walk-a-directory-Recursively/00-TASK.txt
Normal file
14
Task/Walk-a-directory-Recursively/00-TASK.txt
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
;Task:
|
||||
Walk a given directory ''tree'' and print files matching a given pattern.
|
||||
|
||||
|
||||
'''Note:''' This task is for recursive methods. These tasks should read an entire directory tree, not a ''single directory''.
|
||||
|
||||
|
||||
'''Note:''' Please be careful when running any code examples found here.
|
||||
|
||||
|
||||
;Related task:
|
||||
* [[Walk a directory/Non-recursively]] (read a ''single directory'').
|
||||
<br><br>
|
||||
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
L(filename) fs:walk_dir(‘/’)
|
||||
I re:‘.*\.mp3’.match(filename)
|
||||
print(filename)
|
||||
|
|
@ -0,0 +1 @@
|
|||
"*.c" f:rglob \ top of stack now has list of all "*.c" files, recursively
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
INT match=0, no match=1, out of memory error=2, other error=3;
|
||||
|
||||
STRING slash = "/", pwd=".", parent="..";
|
||||
|
||||
PROC walk tree = (STRING path, PROC (STRING)VOID call back)VOID: (
|
||||
[]STRING files = get directory(path);
|
||||
FOR file index TO UPB files DO
|
||||
STRING file = files[file index];
|
||||
STRING path file = path+slash+file;
|
||||
IF file is directory(path file) THEN
|
||||
IF file NE pwd AND file NE parent THEN
|
||||
walk tree(path file, call back)
|
||||
FI
|
||||
ELSE
|
||||
call back(path file)
|
||||
FI
|
||||
OD
|
||||
);
|
||||
|
||||
STRING re sort a68 = "[Ss]ort[^/]*[.]a68$";
|
||||
|
||||
PROC match sort a68 and print = (STRING path file)VOID:
|
||||
IF grep in string(re sort a68, path file, NIL, NIL) = match THEN
|
||||
print((path file, new line))
|
||||
FI;
|
||||
|
||||
walk tree(".", match sort a68 and print)
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
with Ada.Directories; use Ada.Directories;
|
||||
with Ada.Text_IO;
|
||||
|
||||
procedure Test_Directory_Walk is
|
||||
procedure Walk (Name : String; Pattern : String) is
|
||||
procedure Print (Item : Directory_Entry_Type) is
|
||||
begin
|
||||
Ada.Text_IO.Put_Line (Full_Name (Item));
|
||||
end Print;
|
||||
procedure Walk (Item : Directory_Entry_Type) is
|
||||
begin
|
||||
if Simple_Name (Item) /= "." and then Simple_Name (Item) /= ".." then
|
||||
Walk (Full_Name (Item), Pattern);
|
||||
end if;
|
||||
exception
|
||||
when Name_Error => null;
|
||||
end Walk;
|
||||
begin
|
||||
Search (Name, Pattern, (others => True), Print'Access);
|
||||
Search (Name, "", (Directory => True, others => False), Walk'Access);
|
||||
end Walk;
|
||||
begin
|
||||
Walk (".", "*.adb");
|
||||
end Test_Directory_Walk;
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
; list all files at current path
|
||||
print list.recursive "."
|
||||
|
||||
; get all files at given path
|
||||
; and select only the ones we want
|
||||
|
||||
; just select the files with .md extension
|
||||
select list.recursive "some/path"
|
||||
=> [".md" = extract.extension]
|
||||
|
||||
; just select the files that contain "test"
|
||||
select list.recursive "some/path"
|
||||
=> [in? "test"]
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
Loop, %A_Temp%\*.tmp,,1
|
||||
out .= A_LoopFileName "`n"
|
||||
MsgBox,% out
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
directory$ = "C:\Windows\"
|
||||
pattern$ = "*.chm"
|
||||
PROClisttree(directory$, pattern$)
|
||||
END
|
||||
|
||||
DEF PROClisttree(dir$, filter$)
|
||||
LOCAL dir%, sh%, res%
|
||||
DIM dir% LOCAL 317
|
||||
IF RIGHT$(dir$) <> "\" IF RIGHT$(dir$) <> "/" dir$ += "\"
|
||||
SYS "FindFirstFile", dir$ + filter$, dir% TO sh%
|
||||
IF sh% <> -1 THEN
|
||||
REPEAT
|
||||
IF (!dir% AND 16) = 0 PRINT dir$ + $$(dir%+44)
|
||||
SYS "FindNextFile", sh%, dir% TO res%
|
||||
UNTIL res% = 0
|
||||
SYS "FindClose", sh%
|
||||
ENDIF
|
||||
SYS "FindFirstFile", dir$ + "*", dir% TO sh%
|
||||
IF sh% <> -1 THEN
|
||||
REPEAT
|
||||
IF (!dir% AND 16) IF dir%?44 <> &2E THEN
|
||||
PROClisttree(dir$ + $$(dir%+44) + "\", filter$)
|
||||
ENDIF
|
||||
SYS "FindNextFile", sh%, dir% TO res%
|
||||
UNTIL res% = 0
|
||||
SYS "FindClose", sh%
|
||||
ENDIF
|
||||
ENDPROC
|
||||
|
|
@ -0,0 +1 @@
|
|||
PRINT WALK$(".", 1, ".+", TRUE, NL$)
|
||||
|
|
@ -0,0 +1 @@
|
|||
dir /s /b "%windir%\System32\*.exe"
|
||||
|
|
@ -0,0 +1 @@
|
|||
FOR /R C:\Windows\System32 %%F IN (*.DLL) DO ECHO "%%F"
|
||||
|
|
@ -0,0 +1 @@
|
|||
FOR /R C:\Windows\System32 %F IN (*.DLL) DO ECHO "%F"
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
#include "boost/filesystem.hpp"
|
||||
#include "boost/regex.hpp"
|
||||
#include <iostream>
|
||||
|
||||
using namespace boost::filesystem;
|
||||
|
||||
int main()
|
||||
{
|
||||
path current_dir("."); //
|
||||
boost::regex pattern("a.*"); // list all files starting with a
|
||||
for (recursive_directory_iterator iter(current_dir), end;
|
||||
iter != end;
|
||||
++iter)
|
||||
{
|
||||
std::string name = iter->path().filename().string();
|
||||
if (regex_match(name, pattern))
|
||||
std::cout << iter->path() << "\n";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
#include <filesystem>
|
||||
#include <iostream>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
int main() {
|
||||
fs::path current_dir(".");
|
||||
// list all files containing an mp3 extension
|
||||
for (auto &file : fs::recursive_directory_iterator(current_dir)) {
|
||||
if (file.path().extension() == ".mp3")
|
||||
std::cout << file.path().filename().string() << std::endl;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace RosettaRecursiveDirectory
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static IEnumerable<FileInfo> TraverseDirectory(string rootPath, Func<FileInfo, bool> Pattern)
|
||||
{
|
||||
var directoryStack = new Stack<DirectoryInfo>();
|
||||
directoryStack.Push(new DirectoryInfo(rootPath));
|
||||
while (directoryStack.Count > 0)
|
||||
{
|
||||
var dir = directoryStack.Pop();
|
||||
try
|
||||
{
|
||||
foreach (var i in dir.GetDirectories())
|
||||
directoryStack.Push(i);
|
||||
}
|
||||
catch (UnauthorizedAccessException) {
|
||||
continue; // We don't have access to this directory, so skip it
|
||||
}
|
||||
foreach (var f in dir.GetFiles().Where(Pattern)) // "Pattern" is a function
|
||||
yield return f;
|
||||
}
|
||||
}
|
||||
static void Main(string[] args)
|
||||
{
|
||||
// Print the full path of all .wmv files that are somewhere in the C:\Windows directory or its subdirectories
|
||||
foreach (var file in TraverseDirectory(@"C:\Windows", f => f.Extension == ".wmv"))
|
||||
Console.WriteLine(file.FullName);
|
||||
Console.WriteLine("Done.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,103 @@
|
|||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <regex.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <err.h>
|
||||
|
||||
enum {
|
||||
WALK_OK = 0,
|
||||
WALK_BADPATTERN,
|
||||
WALK_NAMETOOLONG,
|
||||
WALK_BADIO,
|
||||
};
|
||||
|
||||
#define WS_NONE 0
|
||||
#define WS_RECURSIVE (1 << 0)
|
||||
#define WS_DEFAULT WS_RECURSIVE
|
||||
#define WS_FOLLOWLINK (1 << 1) /* follow symlinks */
|
||||
#define WS_DOTFILES (1 << 2) /* per unix convention, .file is hidden */
|
||||
#define WS_MATCHDIRS (1 << 3) /* if pattern is used on dir names too */
|
||||
|
||||
int walk_recur(char *dname, regex_t *reg, int spec)
|
||||
{
|
||||
struct dirent *dent;
|
||||
DIR *dir;
|
||||
struct stat st;
|
||||
char fn[FILENAME_MAX];
|
||||
int res = WALK_OK;
|
||||
int len = strlen(dname);
|
||||
if (len >= FILENAME_MAX - 1)
|
||||
return WALK_NAMETOOLONG;
|
||||
|
||||
strcpy(fn, dname);
|
||||
fn[len++] = '/';
|
||||
|
||||
if (!(dir = opendir(dname))) {
|
||||
warn("can't open %s", dname);
|
||||
return WALK_BADIO;
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
while ((dent = readdir(dir))) {
|
||||
if (!(spec & WS_DOTFILES) && dent->d_name[0] == '.')
|
||||
continue;
|
||||
if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, ".."))
|
||||
continue;
|
||||
|
||||
strncpy(fn + len, dent->d_name, FILENAME_MAX - len);
|
||||
if (lstat(fn, &st) == -1) {
|
||||
warn("Can't stat %s", fn);
|
||||
res = WALK_BADIO;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* don't follow symlink unless told so */
|
||||
if (S_ISLNK(st.st_mode) && !(spec & WS_FOLLOWLINK))
|
||||
continue;
|
||||
|
||||
/* will be false for symlinked dirs */
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
/* recursively follow dirs */
|
||||
if ((spec & WS_RECURSIVE))
|
||||
walk_recur(fn, reg, spec);
|
||||
|
||||
if (!(spec & WS_MATCHDIRS)) continue;
|
||||
}
|
||||
|
||||
/* pattern match */
|
||||
if (!regexec(reg, fn, 0, 0, 0)) puts(fn);
|
||||
}
|
||||
|
||||
if (dir) closedir(dir);
|
||||
return res ? res : errno ? WALK_BADIO : WALK_OK;
|
||||
}
|
||||
|
||||
int walk_dir(char *dname, char *pattern, int spec)
|
||||
{
|
||||
regex_t r;
|
||||
int res;
|
||||
if (regcomp(&r, pattern, REG_EXTENDED | REG_NOSUB))
|
||||
return WALK_BADPATTERN;
|
||||
res = walk_recur(dname, &r, spec);
|
||||
regfree(&r);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int r = walk_dir(".", ".\\.c$", WS_DEFAULT|WS_MATCHDIRS);
|
||||
switch(r) {
|
||||
case WALK_OK: break;
|
||||
case WALK_BADIO: err(1, "IO error");
|
||||
case WALK_BADPATTERN: err(1, "Bad pattern");
|
||||
case WALK_NAMETOOLONG: err(1, "Filename too long");
|
||||
default:
|
||||
err(1, "Unknown error?");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
#include <sys/types.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fnmatch.h>
|
||||
#include <fts.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* Compare files by name. */
|
||||
int
|
||||
entcmp(const FTSENT **a, const FTSENT **b)
|
||||
{
|
||||
return strcmp((*a)->fts_name, (*b)->fts_name);
|
||||
}
|
||||
|
||||
/*
|
||||
* Print all files in the directory tree that match the glob pattern.
|
||||
* Example: pmatch("/usr/src", "*.c");
|
||||
*/
|
||||
void
|
||||
pmatch(char *dir, const char *pattern)
|
||||
{
|
||||
FTS *tree;
|
||||
FTSENT *f;
|
||||
char *argv[] = { dir, NULL };
|
||||
|
||||
/*
|
||||
* FTS_LOGICAL follows symbolic links, including links to other
|
||||
* directories. It detects cycles, so we never have an infinite
|
||||
* loop. FTS_NOSTAT is because we never use f->statp. It uses
|
||||
* our entcmp() to sort files by name.
|
||||
*/
|
||||
tree = fts_open(argv, FTS_LOGICAL | FTS_NOSTAT, entcmp);
|
||||
if (tree == NULL)
|
||||
err(1, "fts_open");
|
||||
|
||||
/*
|
||||
* Iterate files in tree. This iteration always skips
|
||||
* "." and ".." because we never use FTS_SEEDOT.
|
||||
*/
|
||||
while ((f = fts_read(tree))) {
|
||||
switch (f->fts_info) {
|
||||
case FTS_DNR: /* Cannot read directory */
|
||||
case FTS_ERR: /* Miscellaneous error */
|
||||
case FTS_NS: /* stat() error */
|
||||
/* Show error, then continue to next files. */
|
||||
warn("%s", f->fts_path);
|
||||
continue;
|
||||
case FTS_DP:
|
||||
/* Ignore post-order visit to directory. */
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check if name matches pattern. If so, then print
|
||||
* path. This check uses FNM_PERIOD, so "*.c" will not
|
||||
* match ".invisible.c".
|
||||
*/
|
||||
if (fnmatch(pattern, f->fts_name, FNM_PERIOD) == 0)
|
||||
puts(f->fts_path);
|
||||
|
||||
/*
|
||||
* A cycle happens when a symbolic link (or perhaps a
|
||||
* hard link) puts a directory inside itself. Tell user
|
||||
* when this happens.
|
||||
*/
|
||||
if (f->fts_info == FTS_DC)
|
||||
warnx("%s: cycle in directory tree", f->fts_path);
|
||||
}
|
||||
|
||||
/* fts_read() sets errno = 0 unless it has error. */
|
||||
if (errno != 0)
|
||||
err(1, "fts_read");
|
||||
|
||||
if (fts_close(tree) < 0)
|
||||
err(1, "fts_close");
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
pmatch(".", "*.c");
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,238 @@
|
|||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <wchar.h>
|
||||
|
||||
/* Print "message: last Win32 error" to stderr. */
|
||||
void
|
||||
oops(const wchar_t *message)
|
||||
{
|
||||
wchar_t *buf;
|
||||
DWORD error;
|
||||
|
||||
buf = NULL;
|
||||
error = GetLastError();
|
||||
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, error, 0, (wchar_t *)&buf, 0, NULL);
|
||||
|
||||
if (buf) {
|
||||
fwprintf(stderr, L"%ls: %ls", message, buf);
|
||||
LocalFree(buf);
|
||||
} else {
|
||||
/* FormatMessageW failed. */
|
||||
fwprintf(stderr, L"%ls: unknown error 0x%x\n",
|
||||
message, error);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Print all files in a given directory tree that match a given wildcard
|
||||
* pattern.
|
||||
*/
|
||||
int
|
||||
main()
|
||||
{
|
||||
struct stack {
|
||||
wchar_t *path;
|
||||
size_t pathlen;
|
||||
size_t slashlen;
|
||||
HANDLE ffh;
|
||||
WIN32_FIND_DATAW ffd;
|
||||
struct stack *next;
|
||||
} *dir, dir0, *ndir;
|
||||
size_t patternlen;
|
||||
int argc;
|
||||
wchar_t **argv, *buf, c, *pattern;
|
||||
|
||||
/* MinGW never provides wmain(argc, argv). */
|
||||
argv = CommandLineToArgvW(GetCommandLineW(), &argc);
|
||||
if (argv == NULL) {
|
||||
oops(L"CommandLineToArgvW");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (argc != 3) {
|
||||
fwprintf(stderr, L"usage: %ls dir pattern\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
dir0.path = argv[1];
|
||||
dir0.pathlen = wcslen(dir0.path);
|
||||
pattern = argv[2];
|
||||
patternlen = wcslen(pattern);
|
||||
|
||||
if (patternlen == 0 ||
|
||||
wcscmp(pattern, L".") == 0 ||
|
||||
wcscmp(pattern, L"..") == 0 ||
|
||||
wcschr(pattern, L'/') ||
|
||||
wcschr(pattern, L'\\')) {
|
||||
fwprintf(stderr, L"%ls: invalid pattern\n", pattern);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Must put backslash between path and pattern, unless
|
||||
* last character of path is slash or colon.
|
||||
*
|
||||
* 'dir' => 'dir\*'
|
||||
* 'dir\' => 'dir\*'
|
||||
* 'dir/' => 'dir/*'
|
||||
* 'c:' => 'c:*'
|
||||
*
|
||||
* 'c:*' and 'c:\*' are different files!
|
||||
*/
|
||||
c = dir0.path[dir0.pathlen - 1];
|
||||
if (c == ':' || c == '/' || c == '\\')
|
||||
dir0.slashlen = dir0.pathlen;
|
||||
else
|
||||
dir0.slashlen = dir0.pathlen + 1;
|
||||
|
||||
/* Allocate space for path + backslash + pattern + \0. */
|
||||
buf = calloc(dir0.slashlen + patternlen + 1, sizeof buf[0]);
|
||||
if (buf == NULL) {
|
||||
perror("calloc");
|
||||
exit(1);
|
||||
}
|
||||
dir0.path = wmemcpy(buf, dir0.path, dir0.pathlen + 1);
|
||||
|
||||
dir0.ffh = INVALID_HANDLE_VALUE;
|
||||
dir0.next = NULL;
|
||||
dir = &dir0;
|
||||
|
||||
/* Loop for each directory in linked list. */
|
||||
loop:
|
||||
while (dir) {
|
||||
/*
|
||||
* At first visit to directory:
|
||||
* Print the matching files. Then, begin to find
|
||||
* subdirectories.
|
||||
*
|
||||
* At later visit:
|
||||
* dir->ffh is the handle to find subdirectories.
|
||||
* Continue to find them.
|
||||
*/
|
||||
if (dir->ffh == INVALID_HANDLE_VALUE) {
|
||||
/* Append backslash + pattern + \0 to path. */
|
||||
dir->path[dir->pathlen] = '\\';
|
||||
wmemcpy(dir->path + dir->slashlen,
|
||||
pattern, patternlen + 1);
|
||||
|
||||
/* Find all files to match pattern. */
|
||||
dir->ffh = FindFirstFileW(dir->path, &dir->ffd);
|
||||
if (dir->ffh == INVALID_HANDLE_VALUE) {
|
||||
/* Check if no files match pattern. */
|
||||
if (GetLastError() == ERROR_FILE_NOT_FOUND)
|
||||
goto subdirs;
|
||||
|
||||
/* Bail out from other errors. */
|
||||
dir->path[dir->pathlen] = '\0';
|
||||
oops(dir->path);
|
||||
goto popdir;
|
||||
}
|
||||
|
||||
/* Remove pattern from path; keep backslash. */
|
||||
dir->path[dir->slashlen] = '\0';
|
||||
|
||||
/* Print all files to match pattern. */
|
||||
do {
|
||||
wprintf(L"%ls%ls\n",
|
||||
dir->path, dir->ffd.cFileName);
|
||||
} while (FindNextFileW(dir->ffh, &dir->ffd) != 0);
|
||||
if (GetLastError() != ERROR_NO_MORE_FILES) {
|
||||
dir->path[dir->pathlen] = '\0';
|
||||
oops(dir->path);
|
||||
}
|
||||
FindClose(dir->ffh);
|
||||
|
||||
subdirs:
|
||||
/* Append * + \0 to path. */
|
||||
dir->path[dir->slashlen] = '*';
|
||||
dir->path[dir->slashlen + 1] = '\0';
|
||||
|
||||
/* Find first possible subdirectory. */
|
||||
dir->ffh = FindFirstFileExW(dir->path,
|
||||
FindExInfoStandard, &dir->ffd,
|
||||
FindExSearchLimitToDirectories, NULL, 0);
|
||||
if (dir->ffh == INVALID_HANDLE_VALUE) {
|
||||
dir->path[dir->pathlen] = '\0';
|
||||
oops(dir->path);
|
||||
goto popdir;
|
||||
}
|
||||
} else {
|
||||
/* Find next possible subdirectory. */
|
||||
if (FindNextFileW(dir->ffh, &dir->ffd) == 0)
|
||||
goto closeffh;
|
||||
}
|
||||
|
||||
/* Enter subdirectories. */
|
||||
do {
|
||||
const wchar_t *fn = dir->ffd.cFileName;
|
||||
const DWORD attr = dir->ffd.dwFileAttributes;
|
||||
size_t buflen, fnlen;
|
||||
|
||||
/*
|
||||
* Skip '.' and '..', because they are links to
|
||||
* the current and parent directories, so they
|
||||
* are not subdirectories.
|
||||
*
|
||||
* Skip any file that is not a directory.
|
||||
*
|
||||
* Skip all reparse points, because they might
|
||||
* be symbolic links. They might form a cycle,
|
||||
* with a directory inside itself.
|
||||
*/
|
||||
if (wcscmp(fn, L".") == 0 ||
|
||||
wcscmp(fn, L"..") == 0 ||
|
||||
(attr & FILE_ATTRIBUTE_DIRECTORY) == 0 ||
|
||||
(attr & FILE_ATTRIBUTE_REPARSE_POINT))
|
||||
continue;
|
||||
|
||||
ndir = malloc(sizeof *ndir);
|
||||
if (ndir == NULL) {
|
||||
perror("malloc");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate space for path + backslash +
|
||||
* fn + backslash + pattern + \0.
|
||||
*/
|
||||
fnlen = wcslen(fn);
|
||||
buflen = dir->slashlen + fnlen + patternlen + 2;
|
||||
buf = calloc(buflen, sizeof buf[0]);
|
||||
if (buf == NULL) {
|
||||
perror("malloc");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Copy path + backslash + fn + \0. */
|
||||
wmemcpy(buf, dir->path, dir->slashlen);
|
||||
wmemcpy(buf + dir->slashlen, fn, fnlen + 1);
|
||||
|
||||
/* Push dir to list. Enter dir. */
|
||||
ndir->path = buf;
|
||||
ndir->pathlen = dir->slashlen + fnlen;
|
||||
ndir->slashlen = ndir->pathlen + 1;
|
||||
ndir->ffh = INVALID_HANDLE_VALUE;
|
||||
ndir->next = dir;
|
||||
dir = ndir;
|
||||
goto loop; /* Continue outer loop. */
|
||||
} while (FindNextFileW(dir->ffh, &dir->ffd) != 0);
|
||||
closeffh:
|
||||
if (GetLastError() != ERROR_NO_MORE_FILES) {
|
||||
dir->path[dir->pathlen] = '\0';
|
||||
oops(dir->path);
|
||||
}
|
||||
FindClose(dir->ffh);
|
||||
|
||||
popdir:
|
||||
/* Pop dir from list, free dir, but never free dir0. */
|
||||
free(dir->path);
|
||||
if (ndir = dir->next)
|
||||
free(dir);
|
||||
dir = ndir;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
(use '[clojure.java.io])
|
||||
|
||||
(defn walk [dirpath pattern]
|
||||
(doall (filter #(re-matches pattern (.getName %))
|
||||
(file-seq (file dirpath)))))
|
||||
|
||||
(map #(println (.getPath %)) (walk "src" #".*\.clj"))
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
fs = require 'fs'
|
||||
|
||||
walk = (dir, f_match, f_visit) ->
|
||||
_walk = (dir) ->
|
||||
fns = fs.readdirSync dir
|
||||
for fn in fns
|
||||
fn = dir + '/' + fn
|
||||
if f_match fn
|
||||
f_visit fn
|
||||
if fs.statSync(fn).isDirectory()
|
||||
_walk fn
|
||||
_walk(dir)
|
||||
|
||||
dir = '..'
|
||||
matcher = (fn) -> fn.match /\.coffee/
|
||||
action = console.log
|
||||
walk dir, matcher, action
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
(ql:quickload :cl-fad)
|
||||
(defun mapc-directory-tree (fn directory &key (depth-first-p t))
|
||||
(dolist (entry (cl-fad:list-directory directory))
|
||||
(unless depth-first-p
|
||||
(funcall fn entry))
|
||||
(when (cl-fad:directory-pathname-p entry)
|
||||
(mapc-directory-tree fn entry))
|
||||
(when depth-first-p
|
||||
(funcall fn entry))))
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
CL-USER> (mapc-directory-tree (lambda (x)
|
||||
(when (equal (pathname-type x) "lisp")
|
||||
(write-line (namestring x))))
|
||||
"lang/")
|
||||
/home/sthalik/lang/lisp/.#bitmap.lisp
|
||||
/home/sthalik/lang/lisp/avg.lisp
|
||||
/home/sthalik/lang/lisp/bitmap.lisp
|
||||
/home/sthalik/lang/lisp/box-muller.lisp
|
||||
/home/sthalik/lang/lisp/displaced-subseq.lisp
|
||||
[...]
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
void main() {
|
||||
import std.stdio, std.file;
|
||||
|
||||
// Recursive breadth-first scan (use SpanMode.depth for
|
||||
// a depth-first scan):
|
||||
dirEntries("", "*.d", SpanMode.breadth).writeln;
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
import 'dart:io' show Directory, Platform, File;
|
||||
|
||||
void main(List<String> args) {
|
||||
var dir = Directory(args[0]);
|
||||
dir.list(recursive: true, followLinks: false).forEach((final cur) {
|
||||
if (cur is Directory) {
|
||||
print("Directory: ${cur.path}");
|
||||
}
|
||||
|
||||
if (cur is File) {
|
||||
print("File: ${cur.path}");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
program Walk_a_directory;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
{$R *.res}
|
||||
|
||||
uses
|
||||
System.IOUtils;
|
||||
|
||||
var
|
||||
Files: TArray<string>;
|
||||
FileName, Directory: string;
|
||||
|
||||
begin
|
||||
Directory := TDirectory.GetCurrentDirectory; // dir = '.', work to
|
||||
Files := TDirectory.GetFiles(Directory, '*.*', TSearchOption.soAllDirectories);
|
||||
|
||||
for FileName in Files do
|
||||
begin
|
||||
Writeln(FileName);
|
||||
end;
|
||||
|
||||
Readln;
|
||||
end.
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
def walkTree(directory, pattern) {
|
||||
for name => file in directory {
|
||||
if (name =~ rx`.*$pattern.*`) {
|
||||
println(file.getPath())
|
||||
}
|
||||
if (file.isDirectory()) {
|
||||
walkTree(file, pattern)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
? walkTree(<file:/usr/share/man>, "rmdir")
|
||||
/usr/share/man/man1/rmdir.1
|
||||
/usr/share/man/man2/rmdir.2
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
defmodule Walk_directory do
|
||||
def recursive(dir \\ ".") do
|
||||
Enum.each(File.ls!(dir), fn file ->
|
||||
IO.puts fname = "#{dir}/#{file}"
|
||||
if File.dir?(fname), do: recursive(fname)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
Walk_directory.recursive
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
ELISP> (directory-files-recursively "/tmp/el" "\\.el$")
|
||||
("/tmp/el/1/c.el" "/tmp/el/a.el" "/tmp/el/b.el")
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
walk_dir(Path, Pattern) ->
|
||||
filelib:fold_files(
|
||||
Path,
|
||||
Pattern,
|
||||
true, % Recurse
|
||||
fun(File, Accumulator) -> [File|Accumulator] end,
|
||||
[]
|
||||
)
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
% Collect every file in the current directory
|
||||
walkdir:walk_dir(".", ".*").
|
||||
|
||||
% Collect every file my .config folder that ends with `rc`
|
||||
walkdir:walk_dir("/home/me/.config/", ".*rc$").
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
open System.IO
|
||||
|
||||
let rec getAllFiles dir pattern =
|
||||
seq { yield! Directory.EnumerateFiles(dir, pattern)
|
||||
for d in Directory.EnumerateDirectories(dir) do
|
||||
yield! getAllFiles d pattern }
|
||||
|
||||
getAllFiles "c:\\temp" "*.xml"
|
||||
|> Seq.iter (printfn "%s")
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
USE: io.directories.search
|
||||
|
||||
"." t [
|
||||
dup ".factor" tail? [ print ] [ drop ] if
|
||||
] each-file
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
require unix/filestat.fs
|
||||
require unix/libc.fs
|
||||
|
||||
: $append ( from len to -- ) 2DUP >R >R COUNT + SWAP MOVE R> R@ C@ + R> C! ;
|
||||
|
||||
defer ls-filter
|
||||
|
||||
: dots? ( name len -- ? ) drop c@ [char] . = ;
|
||||
|
||||
file-stat buffer: statbuf
|
||||
|
||||
: isdir ( addr u -- flag )
|
||||
statbuf lstat ?ior statbuf st_mode w@ S_IFMT and S_IFDIR = ;
|
||||
|
||||
: (ls-r) ( dir len -- )
|
||||
pad c@ >r pad $append s" /" pad $append
|
||||
pad count open-dir if drop r> pad c! exit then ( dirid)
|
||||
begin
|
||||
dup pad count + 256 rot read-dir throw
|
||||
while
|
||||
pad count + over dots? 0= if \ ignore all hidden names
|
||||
dup pad count rot + 2dup ls-filter if
|
||||
cr 2dup type
|
||||
then
|
||||
isdir if
|
||||
pad count + swap recurse
|
||||
else drop then
|
||||
else drop then
|
||||
repeat
|
||||
drop r> pad c!
|
||||
close-dir throw
|
||||
;
|
||||
|
||||
: ls-r ( dir len -- ) 0 pad c! (ls-r) ;
|
||||
|
||||
: c-files ( str len -- ? )
|
||||
dup 3 < if 2drop false exit then
|
||||
+ 1- dup c@ 32 or
|
||||
dup [char] c <> swap [char] h <> and if drop false exit then
|
||||
1- dup c@ [char] . <> if drop false exit then
|
||||
drop true ;
|
||||
' c-files is ls-filter
|
||||
|
||||
: all-files ( str len -- ? ) 2drop true ;
|
||||
' all-files is ls-filter
|
||||
|
||||
s" ." ls-r cr
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
#include "dir.bi"
|
||||
|
||||
Sub listFiles(Byref filespec As String, Byval attrib As Integer)
|
||||
Dim As Integer count = 0
|
||||
Dim As String filename = Dir(filespec, attrib)
|
||||
Do While Len(filename) > 0
|
||||
count += 1
|
||||
Print filename
|
||||
filename = Dir()
|
||||
Loop
|
||||
Print !"\nArchives count:"; count
|
||||
End Sub
|
||||
|
||||
Dim As String mylist = "C:\FreeBASIC\""
|
||||
Print "Directories:"
|
||||
listFiles(mylist & "*", fbDirectory)
|
||||
Print
|
||||
Print "Archive files:"
|
||||
listFiles(mylist & "*", fbArchive)
|
||||
Sleep
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
include "NSLog.incl"
|
||||
|
||||
void local fn EnumerateDirectoryAtURL( dirURL as CFURLRef )
|
||||
NSDirectoryEnumerationOptions options = NSDirectoryEnumerationSkipsPackageDescendants + ¬
|
||||
NSDirectoryEnumerationSkipsHiddenFiles
|
||||
|
||||
DirectoryEnumeratorRef enumerator = fn FileManagerEnumeratorAtURL( dirURL, NULL, options, NULL, NULL )
|
||||
CFURLRef url = fn EnumeratorNextObject( enumerator )
|
||||
while ( url )
|
||||
if ( fn StringIsEqual( fn URLPathExtension( url ), @"fb" ) )
|
||||
NSLog(@"%@",url)
|
||||
end if
|
||||
url = fn EnumeratorNextObject( enumerator )
|
||||
wend
|
||||
end fn
|
||||
|
||||
fn EnumerateDirectoryAtURL( fn FileManagerURLForDirectory( NSDesktopDirectory, NSUserDomainMask ) )
|
||||
|
||||
HandleEvents
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
Walk := function(name, op)
|
||||
local dir, file, e;
|
||||
dir := Directory(name);
|
||||
for e in SortedList(DirectoryContents(name)) do
|
||||
file := Filename(dir, e);
|
||||
if IsDirectoryPath(file) then
|
||||
if not (e in [".", ".."]) then
|
||||
Walk(file, op);
|
||||
fi;
|
||||
else
|
||||
op(file);
|
||||
fi;
|
||||
od;
|
||||
end;
|
||||
|
||||
# This will print filenames
|
||||
Walk(".", Display);
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
Start,Find,Files and Folders,Dropdown: Look in>My Documents,
|
||||
Inputbox: filename>m*.txt,Button:Search
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
Public Sub Main()
|
||||
Dim sTemp As String
|
||||
|
||||
For Each sTemp In RDir("/etc", "*.d")
|
||||
Print sTemp
|
||||
Next
|
||||
|
||||
End
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func VisitFile(fp string, fi os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
fmt.Println(err) // can't walk here,
|
||||
return nil // but continue walking elsewhere
|
||||
}
|
||||
if fi.IsDir() {
|
||||
return nil // not a file. ignore.
|
||||
}
|
||||
matched, err := filepath.Match("*.mp3", fi.Name())
|
||||
if err != nil {
|
||||
fmt.Println(err) // malformed pattern
|
||||
return err // this is fatal.
|
||||
}
|
||||
if matched {
|
||||
fmt.Println(fp)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
filepath.Walk("/", VisitFile)
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
new File('.').eachFileRecurse {
|
||||
if (it.name =~ /.*\.txt/) println it;
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
new File('.').eachFileRecurse ~/.*\.txt/, { println it }
|
||||
|
|
@ -0,0 +1 @@
|
|||
new File('.').eachFileRecurse FILES, ~/.*\.txt/, { println it }
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
new File('.').traverse(
|
||||
type : FILES,
|
||||
nameFilter : ~/.*\.txt/,
|
||||
preDir : { if (it.name == '.svn') return SKIP_SUBTREE },
|
||||
) { println it }
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
import System.Environment
|
||||
import System.Directory
|
||||
import System.FilePath.Find
|
||||
|
||||
search pat = find always (fileName ~~? pat)
|
||||
|
||||
main = do
|
||||
[pat] <- getArgs
|
||||
dir <- getCurrentDirectory
|
||||
files <- search pat dir
|
||||
mapM_ putStrLn files
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
import System.FilePath.Posix
|
||||
import System.Directory
|
||||
import System.IO
|
||||
|
||||
dirWalk :: (FilePath -> IO ()) -> FilePath -> IO ()
|
||||
dirWalk filefunc top = do
|
||||
isDirectory <- doesDirectoryExist top
|
||||
if isDirectory
|
||||
then do
|
||||
files <- listDirectory top
|
||||
mapM_ (dirWalk filefunc . (top </>)) files
|
||||
else filefunc top
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
hSetEncoding stdout utf8
|
||||
hSetEncoding stdin utf8
|
||||
let worker fname
|
||||
| takeExtension fname == ".hs" = putStrLn fname
|
||||
| otherwise = return ()
|
||||
dirWalk worker "."
|
||||
|
|
@ -0,0 +1 @@
|
|||
result = file_search( directory, '*.txt', count=cc )
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
require 'dir'
|
||||
>{."1 dirtree '*.html'
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
import java.io.File;
|
||||
|
||||
public class MainEntry {
|
||||
public static void main(String[] args) {
|
||||
walkin(new File("/home/user")); //Replace this with a suitable directory
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursive function to descend into the directory tree and find all the files
|
||||
* that end with ".mp3"
|
||||
* @param dir A file object defining the top directory
|
||||
**/
|
||||
public static void walkin(File dir) {
|
||||
String pattern = ".mp3";
|
||||
|
||||
File listFile[] = dir.listFiles();
|
||||
if (listFile != null) {
|
||||
for (int i=0; i<listFile.length; i++) {
|
||||
if (listFile[i].isDirectory()) {
|
||||
walkin(listFile[i]);
|
||||
} else {
|
||||
if (listFile[i].getName().endsWith(pattern)) {
|
||||
System.out.println(listFile[i].getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
import java.io.IOException;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
|
||||
public class WalkTree {
|
||||
public static void main(String[] args) throws IOException {
|
||||
Path start = FileSystems.getDefault().getPath("/path/to/file");
|
||||
Files.walkFileTree(start, new SimpleFileVisitor<Path>() {
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file,
|
||||
BasicFileAttributes attrs) throws IOException {
|
||||
if (file.toString().endsWith(".mp3")) {
|
||||
System.out.println(file);
|
||||
}
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
import java.io.IOException;
|
||||
import java.nio.file.*;
|
||||
|
||||
public class WalkTree {
|
||||
public static void main(String[] args) throws IOException {
|
||||
Path start = FileSystems.getDefault().getPath("/path/to/file");
|
||||
Files.walk(start)
|
||||
.filter( path -> path.toFile().isFile())
|
||||
.filter( path -> path.toString().endsWith(".mp3"))
|
||||
.forEach( System.out::println );
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
var fso = new ActiveXObject("Scripting.FileSystemObject");
|
||||
|
||||
function walkDirectoryTree(folder, folder_name, re_pattern) {
|
||||
WScript.Echo("Files in " + folder_name + " matching '" + re_pattern + "':");
|
||||
walkDirectoryFilter(folder.files, re_pattern);
|
||||
|
||||
var subfolders = folder.SubFolders;
|
||||
WScript.Echo("Folders in " + folder_name + " matching '" + re_pattern + "':");
|
||||
walkDirectoryFilter(subfolders, re_pattern);
|
||||
|
||||
WScript.Echo();
|
||||
var en = new Enumerator(subfolders);
|
||||
while (! en.atEnd()) {
|
||||
var subfolder = en.item();
|
||||
walkDirectoryTree(subfolder, folder_name + "/" + subfolder.name, re_pattern);
|
||||
en.moveNext();
|
||||
}
|
||||
}
|
||||
|
||||
function walkDirectoryFilter(items, re_pattern) {
|
||||
var e = new Enumerator(items);
|
||||
while (! e.atEnd()) {
|
||||
var item = e.item();
|
||||
if (item.name.match(re_pattern))
|
||||
WScript.Echo(item.name);
|
||||
e.moveNext();
|
||||
}
|
||||
}
|
||||
|
||||
walkDirectoryTree(dir, dir.name, '\\.txt$');
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
rootpath = "/home/user/music"
|
||||
pattern = r".mp3$"
|
||||
|
||||
for (root, dirs, files) in walkdir(rootpath)
|
||||
for file in files
|
||||
if occursin(pattern, file) println(file) end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
// version 1.2.0
|
||||
|
||||
import java.io.File
|
||||
|
||||
fun walkDirectoryRecursively(dirPath: String, pattern: Regex): Sequence<String> {
|
||||
val d = File(dirPath)
|
||||
require (d.exists() && d.isDirectory())
|
||||
return d.walk().map { it.name }.filter { it.matches(pattern) }.sorted().distinct() }
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val r = Regex("""^v(a|f).*\.h$""") // get all C header files beginning with 'va' or 'vf'
|
||||
val files = walkDirectoryRecursively("/usr/include", r)
|
||||
for (file in files) println(file)
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
// care only about visible files and filter out any directories
|
||||
define dir -> eachVisibleFilePath() => {
|
||||
return with name in self -> eachEntry where #name -> second != io_dir_dt_dir where not(#name -> first -> beginswith('.')) select .makeFullPath(#name -> first)
|
||||
}
|
||||
|
||||
// care only about visible directories and filter out any files
|
||||
define dir -> eachVisibleDir() => {
|
||||
return with name in self -> eachEntry where #name -> second == io_dir_dt_dir where not(#name -> first -> beginswith('.')) select dir(.makeFullPath(#name -> first + '/'))
|
||||
}
|
||||
|
||||
// Recursively walk the directory tree and find all files and directories
|
||||
// return only paths to files
|
||||
define dir -> eachVisibleFilePathRecursive(-dirFilter = void) => {
|
||||
local(files = .eachVisibleFilePath)
|
||||
with dir in .eachVisibleDir
|
||||
where !#dirFilter || #dirFilter(#dir -> realPath)
|
||||
do {
|
||||
#files = tie(#files, #dir -> eachVisibleFilePathRecursive(-dirFilter = #dirFilter))
|
||||
}
|
||||
return #files
|
||||
}
|
||||
|
||||
local(matchingfilenames = array)
|
||||
|
||||
with filepath in dir('/') -> eachVisibleFilePathRecursive
|
||||
where #filepath -> endswith('.lasso')
|
||||
let filename = #filepath -> split('/') -> last
|
||||
do #matchingfilenames -> insert(#filename)
|
||||
|
||||
#matchingfilenames
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
function pathsForDirectoryAndWildcardPattern pDirectory, pWildcardPattern
|
||||
-- returns a return-delimited list of long file names
|
||||
-- the last character in the list is a return, unless the list is empty
|
||||
|
||||
filter files(pDirectory) with pWildcardPattern
|
||||
repeat for each line tFile in it
|
||||
put pDirectory & slash & tFile & cr after tPaths
|
||||
end repeat
|
||||
|
||||
filter folders(pDirectory) without ".."
|
||||
repeat for each line tFolder in it
|
||||
put pathsForDirectoryAndWildcardPattern(pDirectory & slash & tFolder, pWildcardPattern) after tPaths
|
||||
end repeat
|
||||
|
||||
return tPaths
|
||||
end pathsForDirectoryAndWildcardPattern
|
||||
|
|
@ -0,0 +1 @@
|
|||
put pathsForDirectoryAndWildcardPattern(the documents folder, "*.livecode*"
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
local lfs = require("lfs")
|
||||
|
||||
-- This function takes two arguments:
|
||||
-- - the directory to walk recursively;
|
||||
-- - an optional function that takes a file name as argument, and returns a boolean.
|
||||
function find(self, fn)
|
||||
return coroutine.wrap(function()
|
||||
for f in lfs.dir(self) do
|
||||
if f ~= "." and f ~= ".." then
|
||||
local _f = self .. "/" .. f
|
||||
if not fn or fn(_f) then
|
||||
coroutine.yield(_f)
|
||||
end
|
||||
if lfs.attributes(_f, "mode") == "directory" then
|
||||
for n in find(_f, fn) do
|
||||
coroutine.yield(n)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- Examples
|
||||
-- List all files and directories
|
||||
for f in find("directory") do
|
||||
print(f)
|
||||
end
|
||||
|
||||
-- List lua files
|
||||
for f in find("directory", function(self) return self:match("%.lua$") end) do
|
||||
print(f)
|
||||
end
|
||||
|
||||
-- List directories
|
||||
for f in find("directory", function(self) return "directory" == lfs.attributes(self, "mode") end) do
|
||||
print(f)
|
||||
end
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
-- Gets the output of given program as string
|
||||
-- Note that io.popen is not available on all platforms
|
||||
local function getOutput(prog)
|
||||
local file = assert(io.popen(prog, "r"))
|
||||
local output = assert(file:read("*a"))
|
||||
file:close()
|
||||
return output
|
||||
end
|
||||
|
||||
-- Iterates files in given directory
|
||||
local function files(directory, recursively)
|
||||
-- Use windows" dir command
|
||||
local directory = directory:gsub("/", "\\")
|
||||
local filenames = getOutput(string.format("dir %s %s/B/A:A", directory, recursively and '/S' or ''))
|
||||
|
||||
-- Function to be called in "for filename in files(directory)"
|
||||
return coroutine.wrap(function()
|
||||
for filename in filenames:gmatch("([^\r\n]+)") do
|
||||
coroutine.yield(filename)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- Walk "C:/Windows" looking for executables
|
||||
local directory = "C:/Windows"
|
||||
local pattern = ".*%.exe$" -- for finding executables
|
||||
for filename in files(directory, true) do
|
||||
if filename:match(pattern) then
|
||||
print(filename)
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
function walk_a_directory_recursively(d, pattern)
|
||||
f = dir(fullfile(d,pattern));
|
||||
for k = 1:length(f)
|
||||
fprintf('%s\n',fullfile(d,f(k).name));
|
||||
end;
|
||||
|
||||
f = dir(d);
|
||||
n = find([f.isdir]);
|
||||
for k=n(:)'
|
||||
if any(f(k).name~='.')
|
||||
walk_a_directory_recursively(fullfile(d,f(k).name), pattern);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
fn walkDir dir pattern =
|
||||
(
|
||||
dirArr = GetDirectories (dir + "\\*")
|
||||
|
||||
for d in dirArr do
|
||||
(
|
||||
join dirArr (getDirectories (d + "\\*"))
|
||||
)
|
||||
|
||||
append dirArr (dir + "\\") -- Need to include the original top level directory
|
||||
|
||||
for f in dirArr do
|
||||
(
|
||||
print (getFiles (f + pattern))
|
||||
)
|
||||
)
|
||||
|
||||
walkDir "C:" "*.txt"
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
FileNames["*"]
|
||||
FileNames["*.png", $RootDirectory]
|
||||
FileNames["*", {"*"}, Infinity]
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
lfs = require "lfs"
|
||||
|
||||
-- This function takes two arguments:
|
||||
-- - the directory to walk recursively;
|
||||
-- - an optional function that takes a file name as argument, and returns a boolean.
|
||||
find = (fn) => coroutine.wrap ->
|
||||
for f in lfs.dir @
|
||||
if f ~= "." and f ~= ".."
|
||||
_f = @.."/"..f
|
||||
coroutine.yield _f if not fn or fn _f
|
||||
if lfs.attributes(_f, "mode") == "directory"
|
||||
coroutine.yield n for n in find _f, fn
|
||||
|
||||
-- Examples
|
||||
-- List all files
|
||||
print f for f in find "templates"
|
||||
|
||||
-- List moonscript files
|
||||
print f for f in find "templates", => @\match "%.moon$"
|
||||
|
||||
-- List directories
|
||||
print f for f in find "templates", => "directory" == lfs.attributes @, "mode"
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
import Nanoquery.IO
|
||||
|
||||
def get_files(dirname)
|
||||
local_filenames = new(File).listDir(dirname)
|
||||
|
||||
filenames = {}
|
||||
|
||||
for i in range(0, len(local_filenames) - 1)
|
||||
if len(local_filenames) > 0
|
||||
if not new(File, local_filenames[i]).isDir()
|
||||
filenames.append(local_filenames[i])
|
||||
else
|
||||
filenames += get_files(local_filenames[i])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return filenames
|
||||
end
|
||||
|
||||
f = new(File)
|
||||
for file in get_files("/")
|
||||
if lower(f.getExtension(file)) = ".mp3"
|
||||
println file
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
import os, re
|
||||
|
||||
for file in walkDirRec "/":
|
||||
if file.match re".*\.mp3":
|
||||
echo file
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/env ocaml
|
||||
#load "unix.cma"
|
||||
#load "str.cma"
|
||||
open Unix
|
||||
|
||||
let walk_directory_tree dir pattern =
|
||||
let re = Str.regexp pattern in (* pre-compile the regexp *)
|
||||
let select str = Str.string_match re str 0 in
|
||||
let rec walk acc = function
|
||||
| [] -> (acc)
|
||||
| dir::tail ->
|
||||
let contents = Array.to_list (Sys.readdir dir) in
|
||||
let contents = List.rev_map (Filename.concat dir) contents in
|
||||
let dirs, files =
|
||||
List.fold_left (fun (dirs,files) f ->
|
||||
match (stat f).st_kind with
|
||||
| S_REG -> (dirs, f::files) (* Regular file *)
|
||||
| S_DIR -> (f::dirs, files) (* Directory *)
|
||||
| _ -> (dirs, files)
|
||||
) ([],[]) contents
|
||||
in
|
||||
let matched = List.filter (select) files in
|
||||
walk (matched @ acc) (dirs @ tail)
|
||||
in
|
||||
walk [] [dir]
|
||||
;;
|
||||
|
||||
let () =
|
||||
let results = walk_directory_tree "/usr/local/lib/ocaml" ".*\\.cma" in
|
||||
List.iter print_endline results;
|
||||
;;
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
use System.IO.File;
|
||||
|
||||
class Test {
|
||||
function : Main(args : String[]) ~ Nil {
|
||||
if(args->Size() = 2) {
|
||||
DescendDir(args[0], args[1]);
|
||||
};
|
||||
}
|
||||
|
||||
function : DescendDir(path : String, pattern : String) ~ Nil {
|
||||
files := Directory->List(path);
|
||||
each(i : files) {
|
||||
file := files[i];
|
||||
if(<>file->StartsWith('.')) {
|
||||
dir_path := String->New(path);
|
||||
dir_path += '/';
|
||||
dir_path += file;
|
||||
|
||||
if(Directory->Exists(dir_path)) {
|
||||
DescendDir(dir_path, pattern);
|
||||
}
|
||||
else if(File->Exists(dir_path) & dir_path->EndsWith(pattern)) {
|
||||
dir_path->PrintLine();
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
NSString *dir = NSHomeDirectory();
|
||||
NSDirectoryEnumerator *de = [[NSFileManager defaultManager] enumeratorAtPath:dir];
|
||||
|
||||
for (NSString *file in de)
|
||||
if ([[file pathExtension] isEqualToString:@"mp3"])
|
||||
NSLog(@"%@", file);
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
/* REXX ---------------------------------------------------------------
|
||||
* List all file names on my disk D: that contain the string TTTT
|
||||
*--------------------------------------------------------------------*/
|
||||
call SysFileTree "d:\*.*", "file", "FS" -- F get all Files
|
||||
-- S search subdirectories
|
||||
Say file.0 'files on disk'
|
||||
do i=1 to file.0
|
||||
If pos('TTTT',translate(file.i))>0 Then
|
||||
say file.i
|
||||
end
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
/* REXX ---------------------------------------------------------------
|
||||
* List all file names on my disk D: that contain the string TTTT
|
||||
*--------------------------------------------------------------------*/
|
||||
call SysFileTree "*TTTT*.*", "file", "FS" -- F get all Files
|
||||
-- S search subdirectories
|
||||
Say file.0 'files found'
|
||||
do i=1 to file.0
|
||||
If pos('TTTT',translate(file.i))>0 Then
|
||||
say file.i
|
||||
end
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
declare
|
||||
[Path] = {Module.link ['x-oz://system/os/Path.ozf']}
|
||||
[Regex] = {Module.link ['x-oz://contrib/regex']}
|
||||
|
||||
proc {WalkDirTree Root Pattern Proc}
|
||||
proc {Walk R}
|
||||
Entries = {Path.readdir R}
|
||||
Files = {Filter Entries Path.isFile}
|
||||
MatchingFiles = {Filter Files fun {$ File} {Regex.search Pattern File} \= false end}
|
||||
Subdirs = {Filter Entries Path.isDir}
|
||||
in
|
||||
{ForAll MatchingFiles Proc}
|
||||
{ForAll Subdirs Walk}
|
||||
end
|
||||
in
|
||||
{Walk Root}
|
||||
end
|
||||
in
|
||||
{WalkDirTree "." ".*\\.oz$" System.showInfo}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
function findFiles($dir = '.', $pattern = '/./'){
|
||||
$prefix = $dir . '/';
|
||||
$dir = dir($dir);
|
||||
while (false !== ($file = $dir->read())){
|
||||
if ($file === '.' || $file === '..') continue;
|
||||
$file = $prefix . $file;
|
||||
if (is_dir($file)) findFiles($file, $pattern);
|
||||
if (preg_match($pattern, $file)){
|
||||
echo $file . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
findFiles('./foo', '/\.bar$/');
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
This script performs a BFS search with recursion protection
|
||||
it is often faster to search using this method across a
|
||||
filesystem due to a few reasons:
|
||||
|
||||
* filesystem is accessed in native node order
|
||||
* a recursive function is not required allowing infinate depth
|
||||
* multiple directory handles are not required
|
||||
* the file being searched for is often not that deep in the fs
|
||||
|
||||
This method also leverages PHP array hashing to speed up loop
|
||||
detection while minimizing the amount of RAM used to track the
|
||||
search history.
|
||||
|
||||
-Geoffrey McRae
|
||||
Released as open license for any use.
|
||||
*/
|
||||
if ($_SERVER['argc'] < 3) {
|
||||
printf(
|
||||
"\n" .
|
||||
"Usage: %s (path) (search) [stop]\n" .
|
||||
" path the path to search\n" .
|
||||
" search the filename to search for\n" .
|
||||
" stop stop when file found, default 1\n" .
|
||||
"\n"
|
||||
, $_SERVER['argv'][0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$path = $_SERVER['argv'][1];
|
||||
$search = $_SERVER['argv'][2];
|
||||
if ($_SERVER['argc'] > 3)
|
||||
$stop = $_SERVER['argv'][3] == 1;
|
||||
else $stop = true;
|
||||
|
||||
/* get the absolute path and ensure it has a trailing slash */
|
||||
$path = realpath($path);
|
||||
if (substr($path, -1) !== DIRECTORY_SEPARATOR)
|
||||
$path .= DIRECTORY_SEPARATOR;
|
||||
|
||||
$queue = array($path => 1);
|
||||
$done = array();
|
||||
$index = 0;
|
||||
while(!empty($queue)) {
|
||||
/* get one element from the queue */
|
||||
foreach($queue as $path => $unused) {
|
||||
unset($queue[$path]);
|
||||
$done[$path] = null;
|
||||
break;
|
||||
}
|
||||
unset($unused);
|
||||
|
||||
$dh = @opendir($path);
|
||||
if (!$dh) continue;
|
||||
while(($filename = readdir($dh)) !== false) {
|
||||
/* dont recurse back up levels */
|
||||
if ($filename == '.' || $filename == '..')
|
||||
continue;
|
||||
|
||||
/* check if the filename matches the search term */
|
||||
if ($filename == $search) {
|
||||
echo "$path$filename\n";
|
||||
if ($stop)
|
||||
break 2;
|
||||
}
|
||||
|
||||
/* get the full path */
|
||||
$filename = $path . $filename;
|
||||
|
||||
/* resolve symlinks to their real path */
|
||||
if (is_link($filename))
|
||||
$filename = realpath($filename);
|
||||
|
||||
/* queue directories for later search */
|
||||
if (is_dir($filename)) {
|
||||
/* ensure the path has a trailing slash */
|
||||
if (substr($filename, -1) !== DIRECTORY_SEPARATOR)
|
||||
$filename .= DIRECTORY_SEPARATOR;
|
||||
|
||||
/* check if we have already queued this path, or have done it */
|
||||
if (array_key_exists($filename, $queue) || array_key_exists($filename, $done))
|
||||
continue;
|
||||
|
||||
/* queue the file */
|
||||
$queue[$filename] = null;
|
||||
}
|
||||
}
|
||||
closedir($dh);
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
use File::Find qw(find);
|
||||
my $dir = '.';
|
||||
my $pattern = 'foo';
|
||||
my $callback = sub { print $File::Find::name, "\n" if /$pattern/ };
|
||||
find $callback, $dir;
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
sub shellquote { "'".(shift =~ s/'/'\\''/gr). "'" }
|
||||
|
||||
sub find_files {
|
||||
my $dir = shellquote(shift);
|
||||
my $test = shellquote(shift);
|
||||
|
||||
local $/ = "\0";
|
||||
open my $pipe, "find $dir -iname $test -print0 |" or die "find: $!.\n";
|
||||
while (<$pipe>) { print "$_\n"; } # Here you could do something else with each file path, other than simply printing it.
|
||||
close $pipe;
|
||||
}
|
||||
|
||||
find_files('.', '*.mp3');
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use strict; # https://rosettacode.org/wiki/Walk_a_directory/Recursively
|
||||
use warnings;
|
||||
use Path::Tiny;
|
||||
|
||||
path('.')->visit( sub {/\.c$/ and print "$_\n"}, {recurse => 1} );
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
-->
|
||||
<span style="color: #008080;">function</span> <span style="color: #000000;">find_pfile</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">pathname</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">sequence</span> <span style="color: #000000;">dirent</span><span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #7060A8;">match</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"pfile.e"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">dirent</span><span style="color: #0000FF;">[</span><span style="color: #000000;">D_NAME</span><span style="color: #0000FF;">])</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #000080;font-style:italic;">-- return pathname&dirent[D_NAME] -- as below</span>
|
||||
<span style="color: #0000FF;">?</span><span style="color: #000000;">pathname</span><span style="color: #0000FF;">&</span><span style="color: #008000;">"\\"</span><span style="color: #0000FF;">&</span><span style="color: #000000;">dirent</span><span style="color: #0000FF;">[</span><span style="color: #000000;">D_NAME</span><span style="color: #0000FF;">]</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<span style="color: #008080;">return</span> <span style="color: #000000;">0</span> <span style="color: #000080;font-style:italic;">-- non-zero terminates scan</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
|
||||
|
||||
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">walk_dir</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"C:\\Program Files (x86)\\Phix"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">find_pfile</span><span style="color: #0000FF;">,</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span>
|
||||
<!--
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
(let Dir "."
|
||||
(recur (Dir)
|
||||
(for F (dir Dir)
|
||||
(let Path (pack Dir "/" F)
|
||||
(cond
|
||||
((=T (car (info Path))) # Is a subdirectory?
|
||||
(recurse Path) ) # Yes: Recurse
|
||||
((match '`(chop "s@.l") (chop F)) # Matches 's*.l'?
|
||||
(println Path) ) ) ) ) ) ) # Yes: Print it
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
lvars repp, fil;
|
||||
;;; create path repeater
|
||||
sys_file_match('.../*.p', '', false, 0) -> repp;
|
||||
;;; iterate over paths
|
||||
while (repp() ->> fil) /= termin do
|
||||
;;; print the path
|
||||
printf(fil, '%s\n');
|
||||
endwhile;
|
||||
|
|
@ -0,0 +1 @@
|
|||
Get-ChildItem -Recurse -Include *.mp3
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
Get-ChildItem -Recurse |
|
||||
Where-Object { $_.Name -match 'foo[0-9]' -and $_.Length -gt 5MB }
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
Get-ChildItem -Recurse |
|
||||
Where-Object { $_.Name -match 'foo[0-9]' } |
|
||||
ForEach-Object { ... }
|
||||
|
|
@ -0,0 +1 @@
|
|||
| Where-Object { !$_.PSIsContainer }
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
% submitted by Aykayayciti (Earl Lamont Montgomery)
|
||||
% altered from fsaenzperez April 2019
|
||||
% (swi-prolog.discourse-group)
|
||||
test_run :-
|
||||
proc_dir('C:\\vvvv\\vvvv_beta_39_x64').
|
||||
|
||||
|
||||
proc_dir(Directory) :-
|
||||
format('Directory: ~w~n',[Directory]),
|
||||
directory_files(Directory,Files),!, %cut inserted
|
||||
proc_files(Directory,Files).
|
||||
|
||||
proc_files(Directory, [File|Files]) :-
|
||||
proc_file(Directory, File),!, %cut inserted
|
||||
proc_files(Directory, Files).
|
||||
proc_files(_Directory, []).
|
||||
|
||||
proc_file(Directory, File) :-
|
||||
(
|
||||
File = '.',
|
||||
directory_file_path(Directory, File, Path),
|
||||
exists_directory(Path),!,%cut inserted
|
||||
format('Directory: ~w~n',[File])
|
||||
;
|
||||
File = '..',
|
||||
directory_file_path(Directory, File, Path),
|
||||
exists_directory(Path),!,%cut inserted
|
||||
format('Directory: ~w~n',[File])
|
||||
;
|
||||
directory_file_path(Directory, File, Path),
|
||||
exists_directory(Path),!,%cut inserted
|
||||
proc_dir(Path)
|
||||
;
|
||||
directory_file_path(Directory, File, Path),
|
||||
exists_file(Path),!,%cut inserted
|
||||
format('File: ~w~n',[File])
|
||||
;
|
||||
format('Unknown: ~w~n',[File])
|
||||
).
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
?- test_run.
|
||||
File: GMFBridge.ax
|
||||
File: libeay32.dll
|
||||
File: ssleay32.dll
|
||||
File: license.txt
|
||||
Directory: C:\vvvv\vvvv_beta_39_x64/licenses
|
||||
Directory: .
|
||||
Directory: ..
|
||||
File: Apache.txt
|
||||
File: BSD.txt
|
||||
File: LGPL.txt
|
||||
File: MIT.txt
|
||||
File: MPL.txt
|
||||
File: MS-PL-Eula.rtf
|
||||
File: MS-PL.txt
|
||||
File: MSR-SSLA.txt
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
Procedure.s WalkRecursive(dir,path.s,Pattern.s="\.txt$")
|
||||
Static RegularExpression
|
||||
If Not RegularExpression
|
||||
RegularExpression=CreateRegularExpression(#PB_Any,Pattern)
|
||||
EndIf
|
||||
|
||||
While NextDirectoryEntry(dir)
|
||||
If DirectoryEntryType(dir)=#PB_DirectoryEntry_Directory
|
||||
If DirectoryEntryName(dir)<>"." And DirectoryEntryName(dir)<>".."
|
||||
If ExamineDirectory(dir+1,path+DirectoryEntryName(dir),"")
|
||||
WalkRecursive(dir+1,path+DirectoryEntryName(dir)+"\",Pattern)
|
||||
FinishDirectory(dir+1)
|
||||
Else
|
||||
Debug "Error in "+path+DirectoryEntryName(dir)
|
||||
EndIf
|
||||
EndIf
|
||||
Else ; e.g. #PB_DirectoryEntry_File
|
||||
If MatchRegularExpression(RegularExpression,DirectoryEntryName(dir))
|
||||
Debug DirectoryEntryName(dir)
|
||||
EndIf
|
||||
EndIf
|
||||
Wend
|
||||
EndProcedure
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
;- Implementation; Find all .log-files in the C:\Windows tree
|
||||
ExamineDirectory(1,"C:\WINDOWS\","")
|
||||
WalkRecursive(1,"C:\WINDOWS\","\.log$")
|
||||
FinishDirectory(1)
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
from pathlib import Path
|
||||
|
||||
for path in Path('.').rglob('*.*'):
|
||||
print(path)
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
import fnmatch
|
||||
import os
|
||||
|
||||
rootPath = '/'
|
||||
pattern = '*.mp3'
|
||||
|
||||
for root, dirs, files in os.walk(rootPath):
|
||||
for filename in fnmatch.filter(files, pattern):
|
||||
print( os.path.join(root, filename))
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
from fnmatch import fnmatch
|
||||
import os, os.path
|
||||
|
||||
def print_fnmatches(pattern, dir, files):
|
||||
for filename in files:
|
||||
if fnmatch(filename, pattern):
|
||||
print os.path.join(dir, filename)
|
||||
|
||||
os.path.walk('/', print_fnmatches, '*.mp3')
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
from path import path
|
||||
|
||||
rootPath = '/'
|
||||
pattern = '*.mp3'
|
||||
|
||||
d = path(rootPath)
|
||||
for f in d.walkfiles(pattern):
|
||||
print f
|
||||
|
|
@ -0,0 +1 @@
|
|||
dir("/bar/foo", "mp3",recursive=T)
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
Sub printFiles(parentDir As FolderItem, pattern As String)
|
||||
For i As Integer = 1 To parentDir.Count
|
||||
If parentDir.Item(i).Directory Then
|
||||
printFiles(parentDir.Item(i), pattern)
|
||||
Else
|
||||
Dim rg as New RegEx
|
||||
Dim myMatch as RegExMatch
|
||||
rg.SearchPattern = pattern
|
||||
myMatch = rg.search(parentDir.Item(i).Name)
|
||||
If myMatch <> Nil Then Print(parentDir.Item(i).AbsolutePath)
|
||||
End If
|
||||
Next
|
||||
End Sub
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
Dim f As FolderItem = GetFolderItem("C:\Windows\system32")
|
||||
Dim pattern As String = "((?:[a-z][a-z]+))(\.)(dll)" //all file names ending in .dll
|
||||
printFiles(f, pattern)
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
/*REXX program shows all files in a directory tree that match a given search criteria.*/
|
||||
parse arg xdir; if xdir='' then xdir='\' /*Any DIR specified? Then use default.*/
|
||||
@.=0 /*default result in case ADDRESS fails.*/
|
||||
dirCmd= 'DIR /b /s' /*the DOS command to do heavy lifting. */
|
||||
trace off /*suppress REXX error message for fails*/
|
||||
address system dirCmd xdir with output stem @. /*issue the DOS DIR command with option*/
|
||||
if rc\==0 then do /*did the DOS DIR command get an error?*/
|
||||
say '***error!*** from DIR' xDIR /*error message that shows "que pasa". */
|
||||
say 'return code=' rc /*show the return code from DOS DIR.*/
|
||||
exit rc /*exit with " " " " " */
|
||||
end /* [↑] bad ADDRESS cmd (from DOS DIR)*/
|
||||
#=@.rc /*the number of @. entries generated.*/
|
||||
if #==0 then #=' no ' /*use a better word choice for 0 (zero)*/
|
||||
say center('directory ' xdir " has " # ' matching entries.', 79, "─")
|
||||
|
||||
do j=1 for #; say @.j /*show all the files that met criteria.*/
|
||||
end /*j*/
|
||||
exit @.0+rc /*stick a fork in it, we're all done. */
|
||||
|
|
@ -0,0 +1 @@
|
|||
'dir /s /b "%windir%\System32\*.exe"'
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
-> (for ([f (in-directory "/tmp")] #:when (regexp-match? "\\.rkt$" f))
|
||||
(displayln f))
|
||||
... *.rkt files including in nested directories ...
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
use File::Find;
|
||||
|
||||
.say for find dir => '.', name => /'.txt' $/;
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
sub find-files ($dir, Mu :$test) {
|
||||
gather for dir $dir -> $path {
|
||||
if $path.basename ~~ $test { take $path }
|
||||
if $path.d { .take for find-files $path, :$test };
|
||||
}
|
||||
}
|
||||
|
||||
.put for find-files '.', test => /'.txt' $/;
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue