0

Wrote a batch file that was supposed to move folder & file structure from one parent directory to the other on each drive while also combining any existing folders only to find out the MOVE command isnt able to combine. Cannot use Xcopy or Robocopy because they copy the source to the destination and then delete the source. Files/folders being moved are very large, so looking for a solution that will move instead of copy/delete... Code I have written so far is below. Currently it will move the files/folders that don't need to be combined and then use robocopy to do the rest, but its still taking over 24 hours where a manual CTRL+X and CTRL+V for each drive is instant... Anyone able to help?

@echo off
REM Last Edited 12/19/21 2:48PM
REM Enter Old Camera Name, New Camera Name
setlocal enableDelayedExpansion
set OldCamName=%~1
set NewCamName=%~2

REM Determine Camera Physical ID from Camera Name


for /F "skip=1" %%F in ('wmic LogicalDisk WHERE DriveType^=3 GET DeviceID') do (
    echo Moving Low Quality on drive %%F%...    
    set oldDirectory="%%F%\DW Spectrum Media\low_quality\!OldCamName!"
    set newDirectory=%%F%\DW Spectrum Media\low_quality\!NewCamName!
    FOR /d %%i IN (!oldDirectory!\*) DO (
        move /Y "%%i" "!newDirectory!"
        robocopy "%%i" "!newDirectory!\%%~ni" /E /J /MOVE /NJH /NJS
    )
    echo Moving High Quality on drive %%F%...
    set oldDirectory="%%F%\DW Spectrum Media\hi_quality\!OldCamName!"
    set newDirectory=%%F%\DW Spectrum Media\hi_quality\!NewCamName!
    FOR /d %%i IN (!oldDirectory!\*) DO (
        move /Y "%%i" "!newDirectory!"
        robocopy "%%i" "!newDirectory!\%%~ni" /E /J /MOVE /NJH /NJS
    )
)
1
  • What version of Windows? Why not PowerShell? Commented Dec 20, 2021 at 3:26

1 Answer 1

0

If you can use PowerShell, it will simplify things greatly. The Move-Item Cmdlet is all you need.

The Move-Item cmdlet moves an item, including its properties, contents, and child items, from one location to another location. ... When you move an item, it is added to the new location and deleted from its original location.

$PathFormat = '{0}:\DW Spectrum Media\{1}\{2}'
$Qualifiers = @( 'low_quality' , 'hi_quality' )

$OldCamName = Read-Host 'Old Camera Name'
$NewCamName = Read-Host 'New Camera Name'

ForEach ( $DriveLetter in (( Get-Volume | Where DriveType -eq 'Fixed' ).DriveLetter -ne $Null ))
{
    $Qualifiers | ForEach{
        $Splat = @{
            'Path'         = ( $PathFormat -f $DriveLetter , $_ , $OldCamName ) + '\*'
            'Destination'  = $PathFormat -f $DriveLetter , $_ , $NewCamName
        }
        ###   Create destination directory if it doesn't exist
        If ( ! (Test-Path $Splat.Dest) ) { mkdir $Splat.Dest }
        Move-Item @Splat  #Boom! :D
    }
}
1
  • Well I ended up realizing I was going about this in a really crazy way and overcomplicating it. The "new cam" never has any data in it, so I could just delete that new directory and rename the old one, the only thing I needed to keep was the text file so I was able to simplify it and keep it in a batch file. Only reason is I dont have any powershell experience. Commented Dec 24, 2021 at 1:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .