wif LiNoUz/SERVER

배치 예제

크라소니 2014. 5. 1. 13:47

dir /b 결과를 AAA변수에 input

 

--===============================================

for /f %a in ('dir /b') do    set AAA=%a

echo %AAA%

--===============================================

 

tokens=1 delims

tokens 써보자 first  of directory list 뽑는것

 

 

--===============================================

::CMD.EXE batch script to display last  2 lines from a txt file

 

@echo OFF

:: Get the number of lines in the file
set LINES=0
for /f "delims==" %%I in (data.txt) do (
    set /a LINES=LINES+1
)

:: Print the last 10 lines (suggestion to use more courtsey of dmityugov)
set /a LINES=LINES-2
more +%LINES% < data.txt

 

--===============================================

:: 더 간단한 예제

 

@echo off
setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%a in (c:\tmp\foo.txt) do (
set var4=!var3!
set var3=!var2!
set var2=!var1!
set var1=!var!
set var=%%a
)
echo !var4!
echo !var3!
echo !var2!
echo !var1!
echo !var!