Tweets from pichat

pichatTwo songs from the year I created my first web sites. http://t.co/8eHrOA9K + http://t.co/AuWb2etI #video #retro
About 1 day, 1 hour ago from pichat (Mark Seuffert)

Tweets from 600infos

600infosI HAVE NYANED FOR 888.4 SECONDS! http://t.co/JQYOZebv via @nyannyancat
About 1 week, 5 days ago from 600infos (Wolf)

Kopiert eine Liste von Dateien in einer Batch Datei

Copying a list of files with a single batch file

Fileliste als Variable

@echo off
set _files="File1" "File2" "File3"
set _ziel=c:\temp
for %%A in (%_files%) do ( copy "%%~A" "%_ziel%\." )

Fileliste in einer externen Datei

Strukturiert

@echo off
set _filelist=c:\temp\filelist.ini
set _ziel=c:\temp
FOR /F "EOL=#" %%A IN (`%_filelist%`) DO ( 
  echo copy "%%~A" "%_ziel%\."
  copy "%%~A" "%_ziel%\."
)

oder als Einzeiler

@set _filelist=c:\temp\filelist.ini&&set _ziel=c:\temp&&FOR /F "EOL=#" %%A IN (%_filelist%) DO (@echo copy "%%~A" "%_ziel%\.")

filelist.ini

  # Format:
  # Path\File1
  # Path\File2
  File3
  File4

Mit Shift mehr als 9 Parameter übergeben

@echo off
set _ziel=c:\temp
call :cp "File1" "File2" "File3" "File4" "File5" "File6" "File7" "File8" "File9" "File10" "File11" "File12"
goto end

::functions
:cp
 if not "%1" == "" (@echo copy "%~1" "%_ziel%\.") else goto :EOF
  shift 
  goto :cp
  
:end

Komplex

@echo off
set _files="File1" "File2" "File3" "File4" "File5" "File6" "File7" "File8" "File9" "File10" "File11" "File12"
set _ziel=c:\temp
set _i=0
set _exit=0

if not exist "%_ziel%\." md "%_ziel%"

:copy_loop
  set /a _i=%_i%+1
  call :cp %_i%
  if %_exit% EQU 1 goto end
  goto copy_loop

::functions
:cp
  FOR /F "usebackq tokens=%~1 delims=; " %%A IN (`echo %_files% `) DO  (
    if exist "%%~A" (
	@echo copy "%%~A" "%_ziel%\."
    ) else (
        @echo "%%~A" not found EXIT now
        set _exit=1
	goto :EOF
    )
  )
	goto :EOF


:end

MERKE

  • in einer Batchdatei werden die FOR-Variablen mit %% angeben, als direkte Eingabe auf der Kommandozeile mit %
  • vor und nach && kein Leerzeichen
  • innerhalb von () können mehrere Zeilen stehen
  • Wenn Pfad oder Dateinamen keine Leerzeichen enthalten kann man auf ”” verzichten

Translate
Advertisment
  • more about Pichat on http://www.pichat.net
  • C4 - Tiny chat software
  • http://600infos.de
  •    Counter:  09448  Online:  15  Your IP:  38.107.179.240  DNS:  unknown  Page generated in    0.08 sec.