troubleshooting Question

Batch Math Troubles

Avatar of Lee W, MVP
Lee W, MVPFlag for United States of America asked on
Windows Batch
14 Comments1 Solution4219 ViewsLast Modified:
Batch math is my weekness.  I have a small batch file below I'm trying to get to give me specific output.  The batch file is below.  The output I'm getting is below it.  The Output I WANT is below that.

-------------------8<-------Batch File-------------------------
@echo off
@echo off
Setlocal ENABLEDELAYEDEXPANSION
Set Drive=x:
set weeks=5
For /l %%a in (%weeks%,-1,1) Do (
      If %%a == %weeks% (
            echo move %Drive%\Week%%a\*.* %Drive%\Delete
            echo move %Drive%\Week%otherweek%\*.* %Drive%\week%%a
      ) Else (
            If %%a == 1 (
                  echo move %Drive%\CurrentWeek\*.* %Drive%\Week%%a                  
            ) Else (
                  Set OW=%%a
                  Set /a otherWeek=OW-1
                  echo move %Drive%\Week%otherweek%\*.* %Drive%\week%%a
            )      
      )
)
endlocal
-------------------8<-------Batch File-------------------------
-------------------8<-------Actual Output-------------------------
move x:\Week5\*.* x:\Delete
move x:\Week1\*.* x:\week5
move x:\Week1\*.* x:\week4
move x:\Week1\*.* x:\week3
move x:\Week1\*.* x:\week2
move x:\CurrentWeek\*.* x:\Week1
-------------------8<-------Actual Output-------------------------
-------------------8<-------DESIRED Output-------------------------
move x:\Week5\*.* x:\Delete
move x:\Week4\*.* x:\week5
move x:\Week3\*.* x:\week4
move x:\Week2\*.* x:\week3
move x:\Week1\*.* x:\week2
move x:\CurrentWeek\*.* x:\Week1
-------------------8<-------DESIRED Output-------------------------
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 14 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 14 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros