@@Dosbatch_logo@@
FORFILES
is The-Windows-way of finding directories and files.SET /P "MyVar=" || SET "MyVar=My Default Value"
findstr /I /R "@fn @brief" handleStrings.php
Source: Fetch only first line from text file using Windows Batch File @@Stackoverflow_icon@@
(ECHO:A a&ECHO:B b&ECHO:C c)>file.txt
:: Fetch only first line from text file using Windows Batch File - https://stackoverflow.com/a/46134683
ECHO Get first line from file:
SET first_line=
SET /P first_line=<file.txt&CALL ECHO %first_line%
ECHO Get last line from file:
SET last_line=
FOR /F "UseBackQ Delims==" %%A In ("file.txt") DO SET "last_line=%%A"
ECHO %last_line%
On Windows 10 build 17063 or later you can use tar.exe
(Source: Superuser @@Superuser_icon@@ )
C:\> tar -xf archive.zip
@echo off&SETLOCAL enabledelayedexpansion
# ls -l
for /f "tokens=*" %%i in ('dir /a /b /-p /o:gen') do (
SET "_FILE=%%i ."
SET "_ATTRIB=%%~ai ."
SET "_SIZE= %%~zi"
ECHO !_FILE:~0,40! %%~ti !_SIZE:~-11! !_ATTRIB:~0,11!.
)
:: https://stackoverflow.com/a/26493855
:getLastToken
SETLOCAL
for %%a in ("%~2\.") do set "lastPart=%%~nxa"
ENDLOCAL&SET "%~1=%lastPart%"
GOTO :EOF
[!WARNING] You cannot break out of an infinite loop
for /L %%L in ( ) do (
Will hang!
Instead use huge values in loop - and bail out:
set cnt=0
for /L %%L in (0 1 9999) do (
set /a cnt+=1
echo Loop !cnt!
if /I !cnt! GTR 10 goto :break
)
:break
Works nicely