Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if file exist and run a batch file in PowerShell?

Tags:

powershell

This may be a simple question, but I am new to PowerShell and could not find a way to do it. Basically, I have to run a .BAT file if a specified file does not exist. The file name is in a patten like "mmddyyy.dat" in a folder, where mmddyyyy is today's month, day(0 prefix if < 10) and year. Pseudo codes would be something like this:

 $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?
like image 888
David.Chu.ca Avatar asked Nov 13 '09 22:11

David.Chu.ca


1 Answers

The command is :

test-path .\example.txt

Returns True or False

For Docs how about official documentation? That's where I check. http://technet.microsoft.com/en-us/scriptcenter/dd742419.aspx

also eggheadcafe.com has a lot of examples: http://www.eggheadcafe.com/conversationlist.aspx?groupid=2464&activetopiccard=0

Although I haven't tried regex in poweshell this may help you:

http://www.eggheadcafe.com/software/aspnet/33029659/regex-multiline-question.aspx

like image 118
konung Avatar answered Sep 23 '22 12:09

konung