Matt
Matt

Reputation: 27

How do I create a batch loop with array and absolute directory?

I'm currently stucked with writing a piece of batch code for Windows optimization. I personally have two seperate SSD each with RAID 0 and would wish to maximize its their full "random access capabilities" using Symlink so I can have better response time by dividing the work between the seperate drives.

I've written a batch code which allows me to create a symlink between the software folder under appdata, commonfiles, etc and the other drive, but now I have built a new PC and would like create the symbol link all at once.

Q: How do I create a batch loop with array and absolute directory?

What I have tried:

set Arr[0]=Discord
set Arr[0]=Visual Studio

set "x=0"

:SymLoop
if defined Arr[%x%] (
    call (
  
@echo off

REM Create Symbolic Link
    mklink /d "C:\ProgramData\%%Arr[%x%]%%" "B:\ProgramData\%%Arr[%x%]%%"
    mklink /d "C:\Program Files\Common Files\%%Arr[%x%]%%" "B:\Program Files\Common Files\%%Arr[%x%]%%"
    mklink /d "C:\Program Files (x86)\Common Files\%%Arr[%x%]%%" "B:\Program Files (x86)\Common Files\%%Arr[%x%]%%" 
    mklink /d "C:\Program Files (x86)\%%Arr[%x%]%%" "B:\Program Files (x86)\%%Arr[%x%]%%"
    mklink /d "C:\Program Files\%%Arr[%x%]%%" "B:\Program Files\%%Arr[%x%]%%"
    
    mklink /d "%userprofile%\AppData\Local\%%Arr[%x%]%%" "B:\Users\AppData\Local\%%Arr[%x%]%%"
    mklink /d "%userprofile%\AppData\Local\Programs\%%Arr[%x%]%%" "B:\Users\AppData\Local\Programs\%%Arr[%x%]%%"
    mklink /d "%userprofile%\AppData\Roaming\%%Arr[%x%]%%" "B:\Users\AppData\Roaming\%%Arr[%x%]%%"
    mklink /d "%userprofile%\AppData\LocalLow\%%Arr[%x%]%%" "B:\Users\AppData\LocalLow\%%Arr[%x%]%%" 

REM Directory Folder
    mkdir "B:\ProgramData\%%Arr[%x%]%%" 
    mkdir "B:\Program Files\Common Files\%%Arr[%x%]%%" 
    mkdir "B:\Program Files (x86)\Common Files\%%Arr[%x%]%%" 
    mkdir "B:\Program Files (x86)\%%Arr[%x%]%%"
    mkdir "B:\Program Files\%%Arr[%x%]%%"

    mkdir "B:\Users\AppData\Local\%%Arr[%x%]%%"
    mkdir "B:\Users\AppData\Local\Programs\%%Arr[%x%]%%"
    mkdir "B:\Users\AppData\Roaming\%%Arr[%x%]%%"
    mkdir "B:\Users\AppData\LocalLow\%%Arr[%x%]%%" 
pause
)
    set /a "x+=1"
    GOTO :SymLoop
)Pause

Upvotes: 1

Views: 101

Answers (1)

Compo
Compo

Reputation: 38579

Based upon your recent edit, I think you're looking for this:

@For %%G In (
    "Discord"
    "Visual Studio"
) Do @For %%H In (
    "%ProgramData:~2%"
    "%CommonProgramFiles:~2%"
    "%CommonProgramFiles(x86):~2%"
    "%ProgramFiles(x86):~2%"
    "%ProgramFiles:~2%"
    "%LocalAppData:~2%"
    "%LocalAppData:~2%\Programs"
    "%AppData:~2%"
    "%UserProfile:~2%\AppData\LocalLow"
) Do @%SystemRoot%\System32\mklink.exe /D "%SystemDrive%%%~H\%%~G" "B:%%~H\%%~G"

Upvotes: 2

Related Questions