Use the File::Find module
The File::Find module in Perl is used for searching and finding files. Can be used to search for filenames across the file system, using regex to match filenames and looping through any directory structure.
Two methods of the File::Find module
The find method traverses from top to bottom.
The findDepth method iterates from the bottom up.
The File::Find module in Perl is used for searching and finding files. Can be used to search for filenames across the file system, using regex to match filenames and looping through any directory structure.
Two methods of the File::Find module
The find method traverses from top to bottom.
The findDepth method iterates from the bottom up.
Function Prototypes
use File::Find;
find(\&wanted, @directories_to_search);
sub wanted { ... }
where the first argument wanted is a subfunction, a callback function, which you define yourself.
This parameter must be there, even if its content is empty. The second argument is a list of directories, which can also be
is a common string scalar for directory names. Note that the &wanted subroutine needs to be preceded by a backslash escape.
both call in the same format, such as finddepth(\& Del_svn, “.”) , the first argument is the called subfunction, the second argument is the directory, “.”) , the first argument is the called subfunction, the second argument is the directory, “.” represents the current directory. represents the current directory.
#!/usr/bin/perl /usr/bin/perl -w
#Function: The script deletes all .svn files from the current directory and its subdirectories.
# Use: command line type: perl delete_svn.pl
# Save the following code in the file named delete_svn.pl
use strict;
use File::Find;
sub del_svn {
if ($_ eq ".svn") {
system("rm -rf $_");
}
}
finddepth(\&del_svn, ".");
print "finished.\n";
The system function is used to invoke the system command, and RM-RF is used to delete the command under Linux
Read More:
- Prompt 550 remove directory operation failed when FTP delete folder
- Delete files with specified suffix in specified folder under Linux
- Idea always reports errors when using “SVN” to associate projects Error:Cannot run Program “SVN” (in directory “path XXXXXX”): CreateProcess error = 2,
- Linux shell RM deletes all. O suffix files in the subdirectory
- MySQL will delete the data minutes before the current time
- Solution: unable to delete folder (you need permission to perform this operation)
- Cannot checkout from svn:E155004:Run ‘svn cleanup‘ to remove locks(type ‘svn help cleanup ‘ for deta
- The out folder does not appear under the idea project. Set the entire compilation information to the target folder
- ionic android Current working directory is not a Cordova-based project.
- Method of modifying file and folder permission by Chmod command in Linux
- Modifying SVN user name and password in eclipse
- In J2EE Tomcat webapps, there are only folder directories and no files
- Adding project folder in SourceInsight is empty
- svn Key usage violation in certificate has been detected
- Common solutions to errors in checkout or commit of SVN
- Svn warehouse migration in Windows Environment
- Svn notes: error reporting in use
- Docker delete error response from daemon: Conflict: unable to delete xxxxx solution
- Mac bigsur cannot create other directory solutions in the root directory (M1 chip is also applicable)
- Ubuntu “a user name is not in the sudoer folder. It will be reported. ” Solutions for