在Windows上获取带有草莓perl的文件的最后修改日期

时间:2023-01-26 15:01:57

I need to get the info on the file for when it was last modified using a perl script heres the relevant code:

我需要获取文件的信息,以便在使用perl脚本进行上次修改时获取相关代码:

#where $file equals "MyFile.txt"
$backslash = "\\";
$upTwoLayersHelper = "..$backslash..$backslash";
@fileInfo = qx(forfiles /M $file /P $upTwoLayersHelper /C "cmd /c echo @fdate @ftime");

qx is a function in perl that allows the execution of a system command and redirects the output to a variable

qx是perl中的一个函数,它允许执行系统命令并将输出重定向到变量

Ive already looked into using stat and it kept returning

我已经调查过使用stat并且它一直在返回

Dec 31 of like 1960

so this did not work for me :/

所以这对我不起作用:/

I used the variables $backslash and $upTwoLayersHelper to build 'safely' the path since windows likes to use \ rather than / and I tested to make sure that the variables interpolate within the qx(...here...) function call.

我使用变量$ backslash和$ upTwoLayersHelper来构建'安全'路径,因为Windows喜欢使用\而不是/我测试以确保变量在qx(... here ...)函数调用中插入。

My problem is the only output I get is

我的问题是我得到的唯一输出

ECHO is on.

when I print the @fileInfo variable

当我打印@fileInfo变量时

BUT when I run the same command within the qx(...) function call outside of perl, and just in batch from the command line as a command it works and returns the correct date information

但是当我在perl之外的qx(...)函数调用中运行相同的命令时,只是从命令行批处理作为命令它工作并返回正确的日期信息

what am I doing wrong in my perl script?

我在perl脚本中做错了什么?

Thanks for your time!

谢谢你的时间!

1 个解决方案

#1


3  

@fileInfo = qx(for %x in ($file) do echo %~tx);

perhaps?

The cmd command for such purposes is

用于此目的的cmd命令是

for %x in (filename) do echo %~tx

(assign the filename to the metavariable %x , then echo that file's [modification] date)

(将文件名分配给元变量%x,然后回显该文件的[修改]日期)

where the % needs to be %% if executed within a batch rather than from the prompt.

如果在批处理中而不是从提示中执行,则%需要为%%。

ECHO is on. is characteristic of an echo statement with no argument.

ECHO正在开启。是没有参数的echo语句的特征。

I'm not sure what the two directories higher idea is, but if that is where your target file is located, you'd need to nett prefix filename with ..\..\

我不确定两个目录的主意是什么,但如果这是你的目标文件所在的位置,你需要使用.. \ .. \ nett前缀文件名

Perhaps

qx(echo %* whatever)

where whatever is your proposed cmd command will yield what cmd receives after all the escape-character resolutions (%* means "all supplied arguments")

无论您提出的cmd命令是什么,都会产生cmd在所有转义字符解析后收到的内容(%*表示“所有提供的参数”)

#1


3  

@fileInfo = qx(for %x in ($file) do echo %~tx);

perhaps?

The cmd command for such purposes is

用于此目的的cmd命令是

for %x in (filename) do echo %~tx

(assign the filename to the metavariable %x , then echo that file's [modification] date)

(将文件名分配给元变量%x,然后回显该文件的[修改]日期)

where the % needs to be %% if executed within a batch rather than from the prompt.

如果在批处理中而不是从提示中执行,则%需要为%%。

ECHO is on. is characteristic of an echo statement with no argument.

ECHO正在开启。是没有参数的echo语句的特征。

I'm not sure what the two directories higher idea is, but if that is where your target file is located, you'd need to nett prefix filename with ..\..\

我不确定两个目录的主意是什么,但如果这是你的目标文件所在的位置,你需要使用.. \ .. \ nett前缀文件名

Perhaps

qx(echo %* whatever)

where whatever is your proposed cmd command will yield what cmd receives after all the escape-character resolutions (%* means "all supplied arguments")

无论您提出的cmd命令是什么,都会产生cmd在所有转义字符解析后收到的内容(%*表示“所有提供的参数”)