none
Do I Migrate? Merge? or Move folders into existing mirror location so I don't remove original files/folders in doing so. RRS feed

  • Question

  • Purpose: 
    I want to make a script that can check Jack Folder against the contents of a mirror Jack folder for duplicate files/folders; then I want to move the duplicate files to a new folder and move a new folder from one directory to the same location in the other directory.


    Issue: 
    In trying to Move-Item I end up moving the folder out with all files in it and the new one moved in only has the one new file in it.

    Synopsis: 
    I want to merge the new files of my Main folder Jill into the mirror folder Jill, but first want to check for duplicates in the Main Jill and move them to a new folder Ken.

    Example: 
    My Main folder Jack has files I want to move and a folder Jill in it; and in Jill is Tom folder. Then my mirror folder Jack which has duplicate files I want to move to a new folder and then merge the folder Jill that has Tom and Tim folders in it.

    How can I move Tim into the Main Folder without moving the non-duplicate contents of Jack and Jill

    Here is my Script for Powershell 5.0
     
    # Where Is GTA Installed?
    $installData = Get-ItemProperty "HKLM:\Software\Wow6432Node\Rockstar Games\Grand Theft Auto V" | Select-Object InstallFolder
    $installLocation = $installData.InstallFolder

    # If GTA is NOT installed
    if($installLocation -eq $null){
    Write-Error "Could not locate GTA Installation, Please Install before running this script."
    exit
    }

    # Test for Drop Zone, create INE
    if(Test-Path "$($installLocation)/dropZone"){
    $trackedModItems = (Get-ChildItem "$($installLocation)/dropZone")
    }
    else{
    New-Item -path "$($installLocation)/dropZone" -itemtype directory -force
    }

    # Match og files that will be replaced by mods.
    $dict = @{}

    $installedItems = (Get-ChildItem "$($installLocation)")
    $installedItems | ForEach-Object -Proces {Write-Host $_}
    $installedItems | % { $dict.Set_Item($_,1) }
    # Check for existing folders so we don't replace them
    $path = "$($installLocation)/dropZone/$($_)"
    $dest = "$($installLocation)/$($_)"

    if(Test-Path $path){
                $this.CreateFolder($dest);
                Copy-Item -Path "$path\*.*" -Destination $dest;
                Write-Host "Files are copied: from [$path] to [$dest]"};
            
            else
            {
                Write-Output "Source Folder does not exist: [$path]";
            }

    [System.Collections.ArrayList]$modNamesMatchingOrigNames = New-Object System.Collections.ArrayList;
    $scriptBlock = {
    #$modNamesMatchingOrigNames
    $outter = $_
    $dict.Keys | % { if($_.Name -eq $outter){ $modNamesMatchingOrigNames.Add($_.Name)}}
    }
    $trackedModItems | % $scriptBlock

    $preserveScriptBlock = {

    if(Test-Path "$($installLocation)/.ogv"){
    Write-Host "Backup Dir Exists"
    }
    else{
    New-Item -path "$($installLocation)/.ogv" -itemtype directory | %{$_.Attributes = "hidden"}
    }

    $path1 = "$($installLocation)/" + $_
    $path2 = "$($installLocation)/.ogv/" + $_

    Move-Item $path1 $path2
    }

    #Step 1, preserve all original files that are going to be replaced by mods
    $modNamesMatchingOrigNames | % $preserveScriptBlock

    #step 2, move modded files into the mix
    $moveModsScriptBlock = {
    Move-Item "$($installLocation)/dropZone/$($_)" "$($installLocation)/$($_)"
    }

    Get-ChildItem "$($installLocation)/dropZone/" | % $moveModsScriptBlock

    #step 3 play the game (block internet from modded game)
    Set-ExecutionPolicy Unrestricted -Scope Process
    New-NetFirewallRule -Program "$($installLocation)\GTA5.exe" -Action Block -Profile Public, Domain, Private -DisplayName "BlockGTA5TEMP" -Description "Block  GTA" -Direction Outbound
    New-NetFirewallRule -Program "$($installLocation)\GTAVLauncher.exe" -Action Block -Profile Public, Domain, Private -DisplayName "BlockGTALauncherTEMP" -Description "Block  GTA" -Direction Outbound
    New-NetFirewallRule -Program "C:\Program Files (x86)\Rockstar Games\Social Club\subprocess.exe" -Action Block -Profile Public, Domain, Private -DisplayName "BlockGTASCTEMP" -Description "Block  GTA" -Direction Outbound

    $fp = "$($installLocation)\GTAVLauncher.exe"
    Start-Process -FilePath $fp -Wait -Passthru

    Remove-NetFirewallRule -DisplayName "BlockGTA5TEMP"
    Remove-NetFirewallRule -DisplayName "BlockGTALauncherTEMP"
    Remove-NetFirewallRule -DisplayName "BlockGTASCTEMP"

    # step 4 Close game
    # step 5
    $unmoveModsScriptBlock = {
    Move-Item "$($installLocation)/$($_)" "$($installLocation)/dropZone/$($_)"
    }
    $trackedModItems | % $unmoveModsScriptBlock

    # Step 6
    $restoreScriptBlock = {
    Move-Item "$($installLocation)/.ogv/$($_)" "$($installLocation)/$($_)"
    }
    $modNamesMatchingOrigNames | % $restoreScriptBlock
    Set-ExecutionPolicy RemoteSigned -Scope Process

    exit
    Set-ExecutionPolicy Unrestricted -Scope Process
    New-NetFirewallRule -Program "$($installLocation)\GTA5.exe" -Action Block -Profile Public, Domain, Private -DisplayName "BlockGTA5TEMP" -Description "Block  GTA" -Direction Outbound
    New-NetFirewallRule -Program "$($installLocation)\GTAVLauncher.exe" -Action Block -Profile Public, Domain, Private -DisplayName "BlockGTALauncherTEMP" -Description "Block  GTA" -Direction Outbound
    New-NetFirewallRule -Program "C:\Program Files (x86)\Rockstar Games\Social Club\subprocess.exe" -Action Block -Profile Public, Domain, Private -DisplayName "BlockGTASCTEMP" -Description "Block  GTA" -Direction Outbound

    Rename-Item $installLocation "$($installLocation)_Vanilla"
    Rename-Item "$($installLocation)_Mod" $installLocation 

    $fp = "$($installLocation)\GTAVLauncher.exe"
    Start-Process -FilePath $fp -Wait -Passthru

    Rename-Item $installLocation "$($installLocation)_Mod"
    Rename-Item "$($installLocation)_Vanilla" $installLocation

    Remove-NetFirewallRule -DisplayName "BlockGTA5TEMP"
    Remove-NetFirewallRule -DisplayName "BlockGTALauncherTEMP"
    Remove-NetFirewallRule -DisplayName "BlockGTASCTEMP"
    Set-ExecutionPolicy RemoteSigned -Scope Process


    Wednesday, January 27, 2016 1:33 AM

All replies

  • Purpose: 
    I want to make a script that can check Jack Folder against the contents of a mirror Jack folder for duplicate files/folders; then I want to move the duplicate files to a new folder and move a new folder from one directory to the same location in the other directory.


    Issue: 
    In trying to Move-Item I end up moving the folder out with all files in it and the new one moved in only has the one new file in it.

    Synopsis: 
    I want to merge the new files of my Main folder Jill into the mirror folder Jill, but first want to check for duplicates in the Main Jill and move them to a new folder Ken.

    Example: 
    My Main folder Jack has files I want to move and a folder Jill in it; and in Jill is Tom folder. Then my mirror folder Jack which has duplicate files I want to move to a new folder and then merge the folder Jill that has Tom and Tim folders in it.

    How can I move Tim into the Main Folder without moving the non-duplicate contents of Jack and Jill

    Here is my Script for Powershell 5.0
     
    # Where Is GTA Installed?
    $installData = Get-ItemProperty "HKLM:\Software\Wow6432Node\Rockstar Games\Grand Theft Auto V" | Select-Object InstallFolder
    $installLocation = $installData.InstallFolder

    # If GTA is NOT installed
    if($installLocation -eq $null){
    Write-Error "Could not locate GTA Installation, Please Install before running this script."
    exit
    }

    # Test for Drop Zone, create INE
    if(Test-Path "$($installLocation)/dropZone"){
    $trackedModItems = (Get-ChildItem "$($installLocation)/dropZone")
    }
    else{
    New-Item -path "$($installLocation)/dropZone" -itemtype directory -force
    }

    # Match og files that will be replaced by mods.
    $dict = @{}

    $installedItems = (Get-ChildItem "$($installLocation)")
    $installedItems | ForEach-Object -Proces {Write-Host $_}
    $installedItems | % { $dict.Set_Item($_,1) }
    # Check for existing folders so we don't replace them
    $path = "$($installLocation)/dropZone/$($_)"
    $dest = "$($installLocation)/$($_)"

    if(Test-Path $path){
                $this.CreateFolder($dest);
                Copy-Item -Path "$path\*.*" -Destination $dest;
                Write-Host "Files are copied: from [$path] to [$dest]"};
            
            else
            {
                Write-Output "Source Folder does not exist: [$path]";
            }

    [System.Collections.ArrayList]$modNamesMatchingOrigNames = New-Object System.Collections.ArrayList;
    $scriptBlock = {
    #$modNamesMatchingOrigNames
    $outter = $_
    $dict.Keys | % { if($_.Name -eq $outter){ $modNamesMatchingOrigNames.Add($_.Name)}}
    }
    $trackedModItems | % $scriptBlock

    $preserveScriptBlock = {

    if(Test-Path "$($installLocation)/.ogv"){
    Write-Host "Backup Dir Exists"
    }
    else{
    New-Item -path "$($installLocation)/.ogv" -itemtype directory | %{$_.Attributes = "hidden"}
    }

    $path1 = "$($installLocation)/" + $_
    $path2 = "$($installLocation)/.ogv/" + $_

    Move-Item $path1 $path2
    }

    #Step 1, preserve all original files that are going to be replaced by mods
    $modNamesMatchingOrigNames | % $preserveScriptBlock

    #step 2, move modded files into the mix
    $moveModsScriptBlock = {
    Move-Item "$($installLocation)/dropZone/$($_)" "$($installLocation)/$($_)"
    }

    Get-ChildItem "$($installLocation)/dropZone/" | % $moveModsScriptBlock

    #step 3 play the game (block internet from modded game)
    Set-ExecutionPolicy Unrestricted -Scope Process
    New-NetFirewallRule -Program "$($installLocation)\GTA5.exe" -Action Block -Profile Public, Domain, Private -DisplayName "BlockGTA5TEMP" -Description "Block  GTA" -Direction Outbound
    New-NetFirewallRule -Program "$($installLocation)\GTAVLauncher.exe" -Action Block -Profile Public, Domain, Private -DisplayName "BlockGTALauncherTEMP" -Description "Block  GTA" -Direction Outbound
    New-NetFirewallRule -Program "C:\Program Files (x86)\Rockstar Games\Social Club\subprocess.exe" -Action Block -Profile Public, Domain, Private -DisplayName "BlockGTASCTEMP" -Description "Block  GTA" -Direction Outbound

    $fp = "$($installLocation)\GTAVLauncher.exe"
    Start-Process -FilePath $fp -Wait -Passthru

    Remove-NetFirewallRule -DisplayName "BlockGTA5TEMP"
    Remove-NetFirewallRule -DisplayName "BlockGTALauncherTEMP"
    Remove-NetFirewallRule -DisplayName "BlockGTASCTEMP"

    # step 4 Close game
    # step 5
    $unmoveModsScriptBlock = {
    Move-Item "$($installLocation)/$($_)" "$($installLocation)/dropZone/$($_)"
    }
    $trackedModItems | % $unmoveModsScriptBlock

    # Step 6
    $restoreScriptBlock = {
    Move-Item "$($installLocation)/.ogv/$($_)" "$($installLocation)/$($_)"
    }
    $modNamesMatchingOrigNames | % $restoreScriptBlock
    Set-ExecutionPolicy RemoteSigned -Scope Process

    exit
    Set-ExecutionPolicy Unrestricted -Scope Process
    New-NetFirewallRule -Program "$($installLocation)\GTA5.exe" -Action Block -Profile Public, Domain, Private -DisplayName "BlockGTA5TEMP" -Description "Block  GTA" -Direction Outbound
    New-NetFirewallRule -Program "$($installLocation)\GTAVLauncher.exe" -Action Block -Profile Public, Domain, Private -DisplayName "BlockGTALauncherTEMP" -Description "Block  GTA" -Direction Outbound
    New-NetFirewallRule -Program "C:\Program Files (x86)\Rockstar Games\Social Club\subprocess.exe" -Action Block -Profile Public, Domain, Private -DisplayName "BlockGTASCTEMP" -Description "Block  GTA" -Direction Outbound

    Rename-Item $installLocation "$($installLocation)_Vanilla"
    Rename-Item "$($installLocation)_Mod" $installLocation 

    $fp = "$($installLocation)\GTAVLauncher.exe"
    Start-Process -FilePath $fp -Wait -Passthru

    Rename-Item $installLocation "$($installLocation)_Mod"
    Rename-Item "$($installLocation)_Vanilla" $installLocation

    Remove-NetFirewallRule -DisplayName "BlockGTA5TEMP"
    Remove-NetFirewallRule -DisplayName "BlockGTALauncherTEMP"
    Remove-NetFirewallRule -DisplayName "BlockGTASCTEMP"
    Set-ExecutionPolicy RemoteSigned -Scope Process


    This script works to move the new folder but replaces the whole of the original folder. All I want to do is move the duplicates to a new folder first then merge the updated content in. This script is moving the folder with the same name out and putting the folder with the same name in. I want this tool to be fluid in that when new content arrives it will import it as it sees, then remove them when the process is done. This way I can run my modified game without it getting deleted so it moves the original files to another folder and moves the modded files in. When the game stops it moves everything back in where it was when I started.

    Help please......................


    • Edited by Innate Thought Wednesday, January 27, 2016 1:45 AM mispleed wrods. olo
    Wednesday, January 27, 2016 1:43 AM