Hi absolutelyrandom1234,
Is always problematic if the delayed variables are taken in the For-loop - but work is still delayed in "do".
All that comes out is gibberish. Mixing the delayed- with forvariables can be done if there are no special characters to be expected.
Always work with a delay in "in" and if problematic special characters are to be expected, this delayedExpansion must first be deactivated in "do".
Before the variables are declared again or comparisons take place.
It is also possible to work with a call, which means that the delay is no longer applicable - but that only works in very few cases.
If you are looking for batches that use drag and drop correctly, you should search for "drag and drop files".
There are tons of versions and approaches of such batches to transfer files orally.
This version has been modified a little and throws every file/folder onto the disk to match. I removed the unnecessary creation of variables.
If it has become illegible as a result, I may be tortured or forgiven.
Code: Select all
:: ================================================================== ::
:: ======================== Puvox.Software ======================== ::
:: ================================================================== ::
:: ============== Symlink Creator with Drag&Drop v1.3 =============== ::
:: ======= This script makes a symlink of any files/folders ========= ::
:: ========= ( instructions at: https://goo.gl/8vYCDT ) =========== ::
:: ================================================================== ::
:: ================================================================== ::
@rem has been reworked a bit
@echo off
setlocal enableextensions
if "%~1"=="" echo usage: drag and Drop Files to %0 & pause & exit /b 1
set "setMethod="
set /p inputedTargetDir= Path to folder, wherein the symlink will be created: ||goto :end
if ' lss ! setlocal enabledelayedexpansion
for /f eol^=^:delims^=^" %%T in ("!inputedTargetDir!") do (
if ! lss ' endlocal
if exist "%%~T\" ( call :DragAndDropFiles
) else goto :end
)
echo done
:end
pause
exit /b
:DragAndDropFiles ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
@set prompt=$g$s
if ! lss ' (setlocal disabledelayedexpansion) else setlocal
if : == so * what can i do & (
DragAndDropFiles
Drag and drop files/folders through a batch file
the first two lines are skipped because only the cmd calls the batch there.
Quotation marks are included in the variable so that the forLoop recognizes
the variable as a string and not as a file.
Is also required to insert the line break into the variable.
In the for /f loop, all files are output line by line.
So the batch runs without goto.
)
( set \n=^^^
%= The empty line 2 is critical - DO NOT REMOVE =%
)
if ' lss ! setlocal enabledelayedexpansion
set drag="!cmdcmdline!"
set "drag=!drag: "=%\n%
"!"
for /f skip^=2eol^=^:tokens^=1-2delims^=^" %%A in (!drag:" ="%\n%
!) do ( if ! lss ' endlocal
set withoutQ="%%A"
set quoted="%%B"
setlocal enabledelayedexpansion
for /f eol^=^:delims^=^" %%c in (!quoted!!withoutQ:^ ^=%\n%
!) do ( if ! lss ' endlocal
set "NO="
if NOT defined setmethod call :Linkmethod notDefault
if /i "%%~dpc" == "%%~T\" (set prefix="-symlinked-") else set prefix=""
if exist "%%c\" ( rem Folder "%%c"
IF defined NOTdefault ( set linkOption="/J"
) ELSE set linkOption="/D"
) else if exist "%%c" ( rem -file- "%%c"
if defined NOTdefault ( set linkOption="/H"
) ELSE set linkOption=""
) else >&2 echo NOT found "%%c" & "set NO=1"
if Not defined NO (
if ' lss ! setlocal enabledelayedexpansion
for /f "tokens=1,2" %%o in ("!linkOption! !prefix!") do (
if ! lss ' endlocal
mklink %%~o "%%~T\%%~p%%~nxc" "%%c"
)
)
)
)
exit /b
:LinkMethod
set setmethod=1
set "NOTdefault="
rem :: If same drives, then allow user to choose HARD method. Otherwise, only SOFT can be used
for %%. in (.) do if /i "%%~dc" == "%%~dT" (
>&3 echo source and Destinaton drives are same, so you have an opportunity to
call :YesNo "create HARD-SYMLINK press " ", default SOFT-SYMLINK press "
if errorlevel 1 set notDefault=1
)
exit /b
:YesNo Yes No query: [message]Y [message]N
setlocal
set "y=0"
for /f "eol=0 tokens=3,4,6delims=(/) " %%a in (
'"echo n|xcopy /L /-y %windir%\win.ini %windir%\system.ini"'
) do ( <nul set/p"=%~1[%%a]%~2[%%b]%%c "
xcopy /Lpy "%~f0" nul:\* |findstr /b [1-9] >nul && (set /a "y=1" &echo %%a) || echo %%b
)
exit /b %y%