switch statement either powershell or bat file

how would it take and check the current date say for example monday and then do the following
if monday check directory friday
if tuesday check monday
if weds check tuesday
if thurs check weds
if friday check thurs

basically I need to be able to check for files in a directory for the previous day.  Thanks!
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NVITEnd-user supportCommented:
If you can use  yesterday in format YYYYMMDD, then...

With a .bat or .cmd file, you can use something like...
- Yesterdays date in yyyymmdd format

Revise it, removing the PAUSE line.

This returns yesterday in format YYYYMMDD:
for /f "tokens=1-3" %a in ('call yesterday-yyyymmdd.cmd') do echo %c


Open in new window

Bill PrewIT / Software Engineering ConsultantCommented:
This should get the job done.  It determines today's day of the week, and then gets the appropriate prior business day folder.  Should give the concept, let me know questions, or how you need adjusted.

@echo off
setlocal EnableDelayedExpansion

REM Define folder base path
set BaseDir=B:\Base
set DayDir[1]=Friday
set DayDir[2]=Monday
set DayDir[3]=Tuesday
set DayDir[4]=Wednesday
set DayDir[5]=Thursday

REM Get day of week, and then check the prior days folder
call :DayOfWeek DOW
if %DOW% GEQ 1 (
  if %DOW% LEQ 5 (
    echo Check folder: %BaseDir%\!DayDir[%DOW%]!

REM Done
exit /b

:DayOfWeek [return-var]
  REM Sunday = 0
  for /f "skip=2 tokens=2 delims=," %%A in ('WMIC Path Win32_LocalTime Get DayOfWeek /Format:csv') do set "%~1=%%A"
  exit /b

Open in new window

Bill PrewIT / Software Engineering ConsultantCommented:

A slight change of handle I see...

Are You Protected from Q3's Internet Threats?

Every quarter, WatchGuard's Threat Lab releases a security report that analyzes the top threat trends impacting companies around the world. For Q3, we saw that 6.8% of the top 100K websites use insecure SSL protocols. Read the full report to start protecting your business today!

bbimisAuthor Commented:
let me ask you as i'm totally new to powershell here is what i'm trying to acheive.
basically i want to test a directory on a remote system with maybe test-path ?
i can't figure out how to pass it the credientials because normally i would use like get-credientals and then -computername $compname -credientials $creds

so to clarify i want to take and test to see if the files are in the previous days folder
and if so return a true or false and then copy them to another computer which i have the drive networked on my local computer that is running the script.

Any help would be great!
I'm not sure what your naming structure is or exactly what the directory check should be.
Here's an example of a switch statement in PowerShell that does different things depending on the dya of the week.

switch ( (Get-Date).DayOfWeek )
    "Monday"     { "check Friday"; break }
    "Tuesday"    { "check Monday"; break }
    "Wednesday"  { "check Tuesday"; break }
    "Thursday"   { "check Wednesday"; break }
    "Friday"     { "check Thursday"; break }

Open in new window

Bill PrewIT / Software Engineering ConsultantCommented:
So you wanted Powershell, not DOS batch?

NVITEnd-user supportCommented:

Hi Bill.

Yes. With the hope that it would be easier to remember... and type.
Bill PrewIT / Software Engineering ConsultantCommented:

I like it!

bbimisAuthor Commented:
so how do i pass the test-path command to a remote computer or is there something else to use?
test-path c:\somefolderonremote  -computername $compname -credientals $creds

Open in new window

i know this would work for a wmi pass but do i need to pipe it somehow ?
You either need to use a UNC path, or if you have PS Remoting set up you can use local paths (since you would be running the command on the remote server).
Try if this works for you:
#requires -Version 3
$SourceShare = "\\SomeServer\SomeShare"
$SourceUser = "SomeDomain\SomeUser"
$SourceDrive = "Yesterday"
$TargetFolder = "C:\Temp"
New-PSDrive -Name $SourceDrive -Root $SourceShare -Credential (Get-Credential -UserName $SourceUser -Message "Enter credentials for '$($SourceShare)':") -PSProvider FileSystem -ErrorAction Stop
$CheckFolder = Get-Date | ForEach-Object {
	If ("Saturday", "Sunday", "Monday" -contains $_.DayOfWeek) {"Friday"} Else {$_.AddDays(-1).DayOfWeek}
$SourcePath = Join-Path -Path "$($SourceDrive):" -ChildPath $CheckFolder
If ($CopyFiles = Get-ChildItem -Path $SourcePath -File -ErrorAction SilentlyContinue) {
	"Found files in '$($SourcePath)', copying ..." | Write-Host
	$CopyFiles | ForEach-Object {
		"    - $($_.Name)" | Write-Host
		Copy-Item -Path $_.FullName -Destination $TargetFolder -WhatIf
} Else {
	"Found no files in '$($SourcePath)'!" | Write-Warning
Remove-PSDrive -Name $SourceDrive
& net.exe use $SourceShare /delete /y 2>&1 | Out-Null ## Remove-PSDrive doesn't fully clean up after itself

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bbimisAuthor Commented:
thanks got it!
bbimisAuthor Commented:
have a question is there a way to basically go through a whole directory for example

and then look inside the directory(s) and see if you have a modification of the previous day
and then copy those files?

so if i have files in there
file1.txt 8/3/2015
file2.txt 8/5/2015

i would only want to pull over 8/5

Thanks for the help!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.