perl grep dir and filename
my($directory, $filename) = $text =~ m/(.*\/)(.*)$/; print "D=$directory, F=$filename\n
11381 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
my($directory, $filename) = $text =~ m/(.*\/)(.*)$/; print "D=$directory, F=$filename\n
Dir['**/*.jpg'].foreach do |filename| ... do anything with the filename end
Dir['**/*.jpg'].foreach do |filename| ... do anything with the filename end
require 'rexml/document' include REXML class Xmldirectory def initialize end def create_directory_file file = File.new('dir.xml','w') doc = Document.new doc.add_element('dir') Dir["*.xml"].each do |x| entry = Element.new('file') entry.text = x doc.root.add_element entry end file.puts doc file.close end end
/* * * Esempio che scansiona una cartella stampando a video i file in essa * contenuti. */ #include <dirent.h> #include <stdio.h> #include <stdlib.h> #include <sys/types.h> int main(int argc, char *argv[]) { DIR *dir; struct dirent *drent; if(argc < 2) { fprintf(stderr, "%s <directory>\n", argv[0]); return EXIT_FAILURE; } if((dir = opendir(argv[1])) == NULL) { fprintf(stderr, "Errore opendir()\n"); return EXIT_FAILURE; } while((drent = readdir(dir)) != NULL) { fprintf(stdout, "--> %s\n", drent->d_name); } if(closedir(dir) < 0) { fprintf(stderr, "Errore closedir()\n"); return EXIT_FAILURE; } }
load-dir: func [
"Load file info for all files in a directory."
path /local result orig-dir
][
result: copy []
orig-dir: what-dir
change-dir dirize path
foreach file read %. [
repend result [
file
;file: get-modes file 'full-path
make info? file get-modes file get-modes file 'file-modes
]
; include # of files in sub-dirs?
; include full-path?
]
change-dir orig-dir
result
]
ensure-dir-exists: func [dir] [attempt [make-dir/deep dir]]
copy-dir: func [source dest] [
if not exists? dest [make-dir/deep dest]
foreach file read source [
either find file "/" [
copy-dir source/:file dest/:file
][
print file
write/binary dest/:file read/binary source/:file
]
]
]
dir-file-sort: func [
{Returns the block of files with directories first, followed by
files, with each group sorted.}
block [any-block!]
/local result
][
result: copy []
foreach blk lib/ser/split block [:dir?] none [
append result sort blk
]
]
dirs: func [
{Returns a block of fully qualified subdirectories for the directory.}
spec [file!] "Starting directory"
block [block!] "Block to append to"
/deep "Recurse sub-directories."
/local f-spec
][
spec: dirize spec
foreach file read spec [
if dir? f-spec: join spec file [
append block f-spec
if deep [all-dirs/deep f-spec block]
]
]
block
]