这可能是一个简单的问题,但我是PowerShell的新手,无法找到方法.基本上,如果指定的文件不存在,我必须运行.BAT文件.文件名在文件夹中的文件名为" mmddyyy .dat",其中mmddyyyy是今天的月份,日期(如果<10则为0前缀)和年份.伪代码将是这样的:
$File = "C:\temp\*mmddyyyy*.dat" # how to parse Get-Date mmddyyyy and build this pattern?
#if $File exist # check any file exist?
.\myBatch.bat # run the bat file, can I run it in hidden mode?
Run Code Online (Sandbox Code Playgroud)
kon*_*ung 23
命令是:
test-path .\example.txt
Run Code Online (Sandbox Code Playgroud)
返回True或False
对于Docs官方文档怎么样?这是我检查的地方. http://technet.microsoft.com/en-us/scriptcenter/dd742419.aspx
eggheadcafe.com也有很多例子:http://www.eggheadcafe.com/conversationlist.aspx?groupid = 2464&activetopiccard = 0
虽然我没有在poweshell中尝试使用正则表达式,但这可能对您有所帮助:
http://www.eggheadcafe.com/software/aspnet/33029659/regex-multiline-question.aspx
我建议制作一个可重复使用的功能,如下所示:
function GetDateFileName
{
$date = Get-Date
$dateFileName = "$(get-date -f MMddyyyy).dat"
return $dateFileName
}
$fileName = GetDateFileName
$filePath = "c:\temp\" + $fileName
if([IO.File]::Exists($filePath) -ne $true)
{
#do whatever
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14764 次 |
| 最近记录: |