CMD: verschil tussen versies

Uit Mike´s Wiki
Ga naar: navigatie, zoeken
k
k (Lines cmd)
Regel 2: Regel 2:
  
 
{| border="0" cellspacing="0" cellpadding="1" style="border-width: 1px; border-spacing: 2px; font-size:11px;"
 
{| border="0" cellspacing="0" cellpadding="1" style="border-width: 1px; border-spacing: 2px; font-size:11px;"
|+ ''' Shows usage of variables when extended vars are enabled in Windows.'''
+
|+ ''' Shows content of file with line numbers in from of each line.'''
 
|<pre>
 
|<pre>
 
@echo off &setlocal
 
@echo off &setlocal

Versie van 2 okt 2011 om 18:55

Lines cmd

Shows content of file with line numbers in from of each line.
@echo off &setlocal
call :enumerate %1
pause
goto :eof

:enumerate FileName
for /f "tokens=* delims=1234567890" %%a in ('type "%~1"^|findstr /n "^"') do (
  set "line=%%a"
  set /a n+=1
  setlocal enabledelayedexpansion
  echo(!n!. !line:~1!
  endlocal
)
goto :eof

Extended variable usage

Shows usage of variables when extended vars are enabled in Windows.
Parameter to analyse : [ "C:\WINDOWS\system32\user.exe" ]
   %1
  %~1
 %~f1
 %~d1
 %~p1
 %~n1
 %~x1
 %~s1
 %~a1
 %~t1
 %~z1
Actual value
Expands %1 and removes quotes
Expands %1 to a full path
Expands %1 to a drive letter
Expands %1 to a path
Expands %1 to a file name
Expands %1 to a file extension
Expands %1 to a short path name
Expands %1 to a file attributes
Expands %1 to a date and time
Expands %1 to the size of file
 "C:\WINDOWS\system32\user.exe"
 C:\WINDOWS\system32\user.exe
 C:\WINDOWS\system32\user.exe
 C:
 \WINDOWS\system32\
 user
 .exe
 C:\WINDOWS\system32\user.exe
 --a------
 2004-08-04 06:00
 47872
%~PATH:1
 
Searches the path for %1 and expands to the fully qualified name when found in
the PATH variable. When not found, the result is an empty string
 Possible combinations of modifiers you can use to get compound results
%~dp1
%~nx1
%~atzf1
Expands %1 to a drive + path
Expands %1 to a filename + ext
Expands %1 to a dir-like output
C:\WINDOWS\system32\
user.exe
--a------ 2004-08-04 06:00 47872 C:\WINDOWS\system32\user.exe
Shows some other manipulations
%T%
%T:~0,4%
%T:~4%
%D%
%D:~0,2%
%D:~3,2%
%D:~6,2%
%D:~9,4%
%T:~1,-2%
%T%
%T: =%
%T: =_%
The actual value
Fetches left part of the var
Fetches right part of the var
Actual date values
Weekday
Day
Month
Year
Remove 1st and last 2 chars
The actual value
Remove all spaces
Replace space with underscore
Some Text With Spaces
Some
 Text With Spaces
2011-03-16
20
1-
3-
6
ome Text With Space
"Some Text With Spaces "
"SomeTextWithSpaces"
"Some_Text_With_Spaces_"