WebSep 9, 2013 · There are several ways to traverse a directory tree in Perl. It can be done with the function calls opendir and readdir that are part of the Perl language. It can be … WebFeb 4, 2016 · Perl can do this without calling system commands. @secondary=glob("*Secondary*.txt"); print @secondary; @primary=glob("*Primary*.txt") …
file - perl script to recursively list all filename in directory ...
WebApr 14, 2024 · With find . -mindepth 2 -maxdepth 2 you get all elements with a depth of 2 within ., which means every file inside a subdirectory of the current directory (.). In this case, a “file” can be anything: a regular file, a directory, a pipe, etc. you can add the -type f option if you want to remove regular files only: find . -mindepth 2 ... WebJul 16, 2024 · You have missed one simple way to get the modification time of file in perl: the -M switch. my $modifiedTimeinDays = -M "$file"; my $modifiedTimeinSec = $modifiedTimeinDays*60*60*24; if ($modifiedTimeinSec > 60) { # file older than 60 sec } As simple as that. See perldoc -f -X to learn about all of the file tests. Share Follow hassan mousavi
How can I list all of the files in a directory with Perl?
WebI know that glob can look for all files or only all directories inside a folder : echo "All files:\n"; $all = glob ("/*"); var_dump ($all); echo "Only directories\n"; $dirs = glob ("/*", GLOB_ONLYDIR); var_dump ($dirs); But I didn't found something to find only files in a single line efficiently. WebAug 25, 2024 · perl -Mstrict -MFile::Find::Rule -wE' my @files = File::Find::Rule->file->in ("."); say for @files' You can first get the object my $ffr = File::Find::Rule and then set rules on it. The rule ->file only makes it not return directories, while it still recurses. There are many such "rules" to fine tune the behavior. WebOct 16, 2024 · 2 Answers Sorted by: 3 This check will most likely always be wrong because you're looking at the wrong thing. unless (-d $subdir) { $subdir is the filename of a file or directory inside $dir so to access it you need to use the full relative path of $dir/$subdir just like you're doing here: my $size = -s "$dir/$subdir"; puttipaja