Search code examples
batch-filegarrys-mod

Attempting to move folders via batch script moving only contents


I wrote out this batch script to start up a dedicated source server for Garry's Mod in "test mode", where all of the non-essential filesystem addons are moved to a "--Disabled" folder, so that it does not load them into the game. Here's all of the code that may be relevant to that:

mkdir "--Disabled"
cd %gmds%/garrysmod/addons
move advdupe2 --Disabled
move sbep --Disabled
move spacebuild --Disabled
move wire-extras --Disabled
cd %gmds%

The weird thing happens on the third line of that. It tries to move "advdupe2" into "--Disabled", but instead of actually doing that, it shoves only advdupe2's CONTENTS into --Disabled. And the "advdupe2" just gets lost in the matrix or something. At first I thought I messed something up there, but I didn't do anything differently from where I move "sbep", "spacebuild", and "wire-extras", and those 3 move perfectly. Any ideas?

EDIT: I tried putting double quotes around all of the move arguments. Same results.


Solution

  • Wrong order of commands

    cd %gmds%/garrysmod/addons
    mkdir "--Disabled"
    
    move advdupe2 --Disabled
    move sbep --Disabled
    move spacebuild --Disabled
    move wire-extras --Disabled
    

    If the target folder does not exist (and in the original code it was created in the wrong place), the first move command is equivalent to a rename operation, then the following move commands will found that the target folder exists and then the move will be correctly done.