w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
batch create symlinks of all files/folders in a directory
@echo off

    set source=c:sourcedirectory
    set target=c:	argetdirectory
    set exclude=DoNotLinkThisDirectory

    forfiles /P "%source%" /C "cmd /c if @isdir==TRUE (if not
@file=="%exclude%" mklink /d "%target%@file" @path ) else ( mklink
"%target%@file" @path )"

EDIT - Updated to allow "easily" add of multiple excludes, using /G:file if findstr command filter the file/folder list

@echo off

    set "source=c:sourcedirectory"
    set "target=c:	argetdirectory"
    set "exclude=%temp%exclude.txt"

    (
        rem exclude files/dires with these strings into full path
        echo .txt
        echo pipe.cmd

        rem escaped backslash and initial and final quotes to avoid partial
matches
        echo "c:\source\directory\something.txt"

        rem exclude thisNot file/directory from source directory
        echo "%source:=\%\thisNot"

    )> "%exclude%"

    forfiles /P "%source%" /C "cmd /c (echo @path|findstr /i /v
/g:"%exclude%" >nul) && if @isdir==TRUE (mklink /d
"%target%\"@file @path) else (mklink "%target%\"@file @path)"

    del "%exclude%" > nul




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.