这是我的问题:我们有一个文件服务器 (Windows 2003),人们不断在上面放置包含 PII 的表单。现在的政策是,我们的文件服务器上的任何表格都不再允许个人 SSN 的最后 4 位。我正在尝试找出一个脚本来扫描文档中的字符串,例如“SSN”或“Last Four”,我所能找到的只是关于如何在本地机器上搜索文本文件的说明/示例。我见过很多与此类似的线程,但主要是在本地文件夹中搜索 txt 文件。我见过这样做的 powershell 脚本,但是(不要问为什么)我们的服务器上禁用了 powershell 脚本。
这可能吗?我一直在大量阅读多本 Perl 书籍,希望能找到线索或让我朝着正确的方向前进,但运气为 0。
最佳答案
假设您最终可以访问这些文件,下面介绍了如何搜索文件目录,寻找字符串匹配项。
use strict;
use warnings;
use File::Find;
our $CHECK_FILE_EXTENSION = qr/.txt$/;
File::Find::find({wanted=>\&find_ssn, no_chdir=>1},$_) for @ARGV;
exit;
sub find_ssn
{
## File::Find sets $File::Find::name with full path to file, which is the correct path to an 'open' call when 'no_chdir' is used
return unless $File::Find::name =~ $CHECK_FILE_EXTENSION;
open F,$File::Find::name || die "Can't read file, $File::Find::name, $!\n";
while(<F>)
{
if(/SSN/)
{
## file as 'SSN' in it, do your work here
}
}
close F;
}
关于windows - 在网络驱动器上的文件中搜索字符串的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12823998/