RETROBAT Official Board
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Script for Symlink creation NEW VERSION

2 posters

Go down

Script for Symlink creation NEW VERSION Empty Script for Symlink creation NEW VERSION

Post by dragoonluver 07/08/24, 04:46 pm

Hey All,

I am unable to donate to RetroBat right now due to tight funds. However, I have created a script that some might find beneficial.

The process outlined on the wiki for creating symlinks is fine but powershell can do all the symlinks at once Smile

So I have created two scripts. One for use for local drives. Like a secondary drive or external hard drive. The next is a script if you are running your roms on a NAS.

Hopefully it is helpful to someone!

EDIT: Updating the network version of the script. This verifies there is no files present in the directory where symlinks are being created. Future versions will have local and network functionality merged together. I have used this script for my ROMs directory and saves directory.

Code:

#This is for local use like when you have a external hard drive with all your ROMs
#Directory where your Rom files live
$SourceRomDir = "s:\retrobat\roms"
#Directory Where Retrobat is installed and ROMs folder is
$LocalRetroBatDir = "C:\Retrobat\roms"
#Gets names of folders in your source directory
$directories = Get-ChildItem $SourceRomDir
#Loops through each folder and creates Symlink
foreach($dir in $directories.name)
    {
        
        New-Item -ItemType SymbolicLink -path "$LocalRetroBatDir\$dir" -target "$SourceRomDir\$dir"
        
        }

Code:

#This is for network use like when you have your ROMs on a NAS
#Static Variables
#verification nas:\ is not in use
$TestPath = test-path nas:\
#Directory where your Rom files live
$SourceRomDir = "nas:\retrobat\saves"
#Drirectory Where Retrobat is installed and ROMs folder is
$LocalRetroBatDir = "C:\Retrobat\saves"
#friendly name of sahred drived map
$PSDriveName = "nas"
#UNC Path to shared folder where Root folder RetroBat is (I have the entire folder tree mirrored to my nas by installing retrobat there you can use something like robocopy to do this if you dont have a windows backend)
$SharePath = "\\192.168.1.1\NAS"
#Gets items in specified $LocalRetroBatDir if null it means the directory is empty
$TestEmptyDirectory = Get-ChildItem $LocalRetroBatDir
#Gets names of folders in your source directory
$directories = Get-ChildItem $SourceRomDir
#Assists in stopping the user before deletion happens
$WarningPreference = "Inquire"

#Test if shared drive is already mapped
if($TestPath -eq $true)

    {
   
    #Removes drive with conflicting name
    Remove-PSDrive -Name $PSDriveName -Force
    #Create temporary drive with your retro bat files
    New-PSDrive -Name $PSDriveName -PSProvider "FileSystem" -Root $SharePath
   
   
    }

#Test if shared drive is not mapped
elseif($TestPath -eq $false)
   
    {
   
   
    #Create temporary drive with your retro bat files
    New-PSDrive -Name $PSDriveName -PSProvider "FileSystem" -Root $SharePath
   
   
    }

#Test if the directory where symlinks are being created is clean
if($TestEmptyDirectory -eq $null)

    {

   
    #Loops through each folder and creates Symlink
    foreach($dir in $directories.name)
   
        {
        #Creating symlinks
        New-Item -ItemType SymbolicLink -path "$LocalRetroBatDir\$dir" -target "$SourceRomDir\$dir"
       
        }

    }

else
        {
       
        Write-Warning "****WARNING****`n BY ALLOWING THIS SCRIPT TO RUN FUTHER YOU ARE MAKING THE CHOICE TO DELETE ITEMS IN THE PATH YOU SPECFIED INCLUDING ALL NESTED ITEMS `n IF YOU ARE UNSURE OR WANT TO STOP DO SO NOW!!!!  `n ****WARNING****"
        #Removes items in the directory where symlinks are going
        remove-item $LocalRetroBatDir\* -Recurse
        #Loops through each folder and creates Symlink
        foreach($dir in $directories.name)
       
       
        {
 
            #Creating symlinks
            New-Item -ItemType SymbolicLink -path "$LocalRetroBatDir\$dir" -target "$SourceRomDir\$dir"
           
        }

}


Last edited by dragoonluver on 15/08/24, 03:21 pm; edited 1 time in total
dragoonluver
dragoonluver

Messages : 2
Date d'inscription : 2024-08-07

Back to top Go down

Script for Symlink creation NEW VERSION Empty Re: Script for Symlink creation NEW VERSION

Post by tartifless 07/08/24, 07:16 pm

Hello,

You could just symlink the full roms folder


Script for Symlink creation NEW VERSION Admin4
tartifless
tartifless
Admin

Messages : 1674
Date d'inscription : 2021-04-27

Back to top Go down

Script for Symlink creation NEW VERSION Empty Re: Script for Symlink creation NEW VERSION

Post by dragoonluver 07/08/24, 08:07 pm

That is a good point. However, I try to keep within the vendors specs:
https://wiki.retrobat.org/tutorials/symbolic-links

They show each emulator getting its own Symlink.

Classic me making things harder than it needs to be XD
dragoonluver
dragoonluver

Messages : 2
Date d'inscription : 2024-08-07

Back to top Go down

Script for Symlink creation NEW VERSION Empty Re: Script for Symlink creation NEW VERSION

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum