简体   繁体   English

使用Perl动态查找文件夹

[英]Dynamic folder finding using perl


Am new to perl and we have a requirement to pickup files from folder that gets created everyday. 这是perl的新功能,我们需要从每天创建的文件夹中提取文件。
Is there any way we can do this like using sysdate or anything? 有什么办法可以像使用sysdate一样执行此操作?
Path will be something like http:\\\\com.test.ci\\test01 \\new_folder_created_daily\\*.* 路径将类似于http:\\\\ com.test.ci \\ test01 \\ new_folder_created_daily \\ *。*
Is there anyway to dynamically get this done ? 无论如何,有没有动态地做到这一点?

I'm making assumptions that you want to act on just the most recently created folder. 我假设您只想对最近创建的文件夹执行操作。 I'm also going to assume you want to wait until the next day as maybe the folder is written to throughout the day... If not, just ignore the $yesterday stuff and use $today instead. 我还要假设您要等到第二天,因为文件夹可能会整天被写入...如果没有,则忽略$yesterday内容并改用$today

Use Time::Piece and Time::Seconds, which have been a core module since 5.009005. 使用时间::件和时间::秒,这是自5.009005开始的核心模块。

use Time::Piece;
use Time::Seconds;

my $today = localtime;
my $yesterday = $today - ONE_DAY;
my $folder = $yesterday->mdy("");

print $folder . "\n"

# do stuff to http:\\com.test.ci\test01\$folder  

Basically we create a Time::Piece object and minus one day from it using a contant from Time::Seconds to create $yesterday . 基本上,我们创建一个Time :: Piece对象,并使用Time :: Seconds中的对数减去它的一天来创建$yesterday We don't really care about the time, so format it as mdy and append it to your parent path. 我们并不真正在乎时间,因此将其格式化为mdy并将其附加到您的父路径中。

The mdy("") just means no delimter between the m, d and y. mdy(“”)仅表示m,d和y之间没有偏斜。 If you instead wrote $yesterday->mdy() , it would format it as MM-DD-YYYY. 如果改为编写$yesterday->mdy() ,则它将其格式设置为MM-DD-YYYY。 Refer to Time::Piece on CPAN for more information on date formatting, calculations, comparisons, and parsing. 有关日期格式,计算,比较和解析的更多信息,请参考CPAN上的Time :: Piece

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM