0

I would like to have a simple .bat file at so that when I double click on the batch file, it opens a new instance of Explorer at C:\Temp\Downloads\YYYYMMDD\ where YYYYMMDD is todays date.

I would think the Old Skool .bat file is the best way to go, but I can't get the date variable to feed through to the Start Explorer command. I dont think I can use PowerShell as the .ps1 is does not run when you double click on the program hence why I think the .bat would work better?

Many thanks, Bertie

P.s. I have the following PS1 Script that I can call from a .bat using PowerShell .\MyPowershell.PS1

$TodaysDate = Get-Date -format "yyyyMMdd"
$PathTarget = 'W:\Counterparty1\Statements\'
$LaunchFolder = $PathTarget + $TodaysDate
Explorer $LaunchFolder
JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Bertie
  • 1,163
  • 3
  • 14
  • 26
  • possible duplicate of [How to append a date in batch files](http://stackoverflow.com/questions/864718/how-to-append-a-date-in-batch-files) – Raymond Chen Nov 02 '11 at 14:24

2 Answers2

1
@echo off
for /F "tokens=1-3 delims=/" %%a in ("%date%") do set TodaysDate=%%c%%a%%b
explorer "C:\Temp\Downloads\%TodaysDate%\"
Aacini
  • 65,180
  • 12
  • 72
  • 108
1

I'd strongly suggest not relying on %date% because your batch script might break on systems with other regional settings.

Here's how to do it using wmi:

@echo off

FOR /F "skip=1 tokens=1-6" %%A IN 
('WMIC Path Win32_LocalTime Get Day^,Hour^,Minute^,Month^,Second^,Year /Format:table')
DO (
SET /A TODAY=%%F*10000+%%D*100+%%A
)
explorer "C:\Temp\Downloads\%TODAY%\"
jon Z
  • 15,838
  • 1
  • 33
  • 35