@echo off&set FileName=%~n0&shift :: ============================================= :: AutoHelp PlugLab Concept: 2006 by Reatogo :: ============================================= :: Help Info: :: ======================= set Routine_Type=3 :: 1=Getting Data 2=Prompts 3=Getting Files 4=Creating Files 5=General set Routine_Vers=1 set Routine_Date=2007-04-20 set RoutineName=GetFolder set RoutineAuthor=Siegfried set Using_work_from= set Example_call_1=%%GetFolder%% "SourceDirectory" "TargetDirectory" set Example_call_2=%%GetFolder%% set Example_call_3= set text_01=The "%%GetFolder%%" routine is the main instrument to copy files to the plugin. It works like xCOPY but allows for cleanup of unwanted files and derives Source-Target from the script environment where possible. The variables "%%MainExe%%" and "%%SubDir_Of_MainEXE%%" are used for this if "%%GetFolder%%" is called without parameters. set text_02=. set text_03=Any source-target may be specified and the "Exclude-ButKeep" feature is used to clean out the unwanted files. set text_04=. set text_05=If "%%GetFolder%%" is used without parameters, "%%ProgPath%% - Files" are assumed as "Source - Target". set text_06=If %%Progpath%% is not defined yet, a call on %%GetProgpath%% is internally done by %%GetFolder%%. So the following type of call is normally all, thatīs needed to copy the files: set text_07=. set text_08=set Exclude=*.txt,*.chm,Lang\*.lng,*uninstall*.*,Links,Skins\*.skn, set text_09=set ButKeep=Lang\%%LANG%%.lng,%%LANG%%.chm,ReadMe.txt,Skins\default.skn, set text_10=%%GetFolder%% set text_24=. set text_25=Use the "%%Exclude%% - %%ButKeep%%" feature to cleanUp the target folder: set text_26=set Exclude=Lang\*.awl, set text_27=set ButKeep=Lang\%%LANG%%.awl, set text_28=%%GetFolder%% set text_29=. set text_30=This will only keep "Files\Lang\german.awl" on a german system. set text_31=The Exclude-ButKeep feature provides a simple way to remove any unwanted files from the target folder. set text_32=Specify any number of exclusions delimited by comma ",". set text_33=%%ButKeep%% can only be used together with %%Exclude%%. It is used to define one or several exceptions for a bulk-exclusion. A typical usage is in the context of language files cleanup. set text_34=. set text_35=The Exclude-ButKeep feature is available for the following routines: set text_36=%%GetFolder%%, %%xDWLD%% and %%Extract%% if "%~1" == "GetHelp" goto :EOF echo.&echo %* :: ============================================= if not "%~1" == "" goto PreCheckDone if defined PROGPATH goto PreCheckDone if not defined MainExe goto :EOF %GetPROGPATH% if not exist "%PROGPATH%\%SubDir_Of_MainEXE%%MainExe%" goto :EOF :PreCheckDone if "%~1" == "" set SourceCopyFiles="%PROGPATH%\*.*"&goto DoRawParam2 set RawParam1=%~1 if "%RawParam1:~-1%" == "\" set AdjParam1=%RawParam1:~0,-1%&goto AdjParam1Set if "%RawParam1:~-4%" == "\*.*" set AdjParam1=%RawParam1:~0,-4%&goto AdjParam1Set set AdjParam1=%RawParam1% :AdjParam1Set set SourceCopyFiles="%AdjParam1%\*.*" :DoRawParam2 if "%~2" == "" set TargetCopyDir=Files&goto DoCopy set RawParam2=%~2 set TargetCopyDir=%~2 if "%RawParam2:~-1%" == "\" set TargetCopyDir=%RawParam2:~0,-1% :DoCopy %MSG% "Copy %SourceCopyFiles:~1,-1%" xcopy %SourceCopyFiles% "%TargetCopyDir%" /I /E /R /Y /C /H :: Preserve the %ButKeep% files before delete the excluded files and folders as per %Exclude% variable if "%ButKeep%" == "" goto NoButKeep if not exist ButKeep md ButKeep SETLOCAL ENABLEDELAYEDEXPANSION set cn=1 :tokloop1 for /f "tokens=%cn% delims=," %%i in ("%ButKeep%") do ( if "%%i"=="" goto tokloopDone1 if exist "%TargetCopyDir%\%%i\*.*" ( xcopy "%TargetCopyDir%\%%i\*.*" "ButKeep\%TargetCopyDir%\%%i" /I /E /R /Y /C /H echo Preserve: "%TargetCopyDir%\%%i" ) else ( set folder=%%~dpi set folder=!folder:%CD%\=! if "!folder:~-1!" == "\" set folder=!folder:~0,-1! echo Preserve: "%TargetCopyDir%\%%i" if exist "%TargetCopyDir%\%%i" ( if not exist "ButKeep\%TargetCopyDir%\!folder!" md "ButKeep\%TargetCopyDir%\!folder!" copy "%TargetCopyDir%\%%i" "ButKeep\%TargetCopyDir%\%%i" ) ) set /a cn +=1 goto tokloop1 ) :tokloopDone1 ENDLOCAL :NoButKeep :: delete the excluded files and folders as per %Exclude% variable if "%exclude%" == "" goto tokloopDone2 set cn=1 :tokloop2 for /f "tokens=%cn% delims=," %%a in ("%exclude%") do ( if "%%a"=="" goto tokloopDone2 if exist "%TargetCopyDir%\%%a\*.*" ( rd "%TargetCopyDir%\%%a" /s /q echo Excluding: "%TargetCopyDir%\%%a" ) else ( echo Excluding: "%TargetCopyDir%\%%a" if exist "%TargetCopyDir%\%%a" del "%TargetCopyDir%\%%a" /q ) set /a cn +=1 goto tokloop2 ) :tokloopDone2 :: Copy the "ButKeep items" back in after the cleanup if not "%ButKeep%" == "" ( xcopy "ButKeep\%TargetCopyDir%\*.*" "%TargetCopyDir%" /I /E /R /Y /C /H if exist ButKeep rd ButKeep /s /q ) if "%TargetCopyDir%" == "Files" if "%Using_1x1Script%" == "yes" if not exist "Files\%StartFile%" copy "SCRIPTS\%StartFile%" "Files\%StartFile%" set TargetCopyDir= set SourceCopyFiles= set RawParam1= set RawParam2= set AdjParam1= set exclude= set ButKeep= goto :EOF