Unfortunately I know very little about DOS batch scripts hence asking for some help...
Code: Select all
@echo off
set path=%1
for %%A in (%path%) do set X=%%~aA
set D=%X:~0,1%
if %D% EQU d (echo directory) else (echo file)
Moderator: DosItHelp
Code: Select all
@echo off
set path=%1
for %%A in (%path%) do set X=%%~aA
set D=%X:~0,1%
if %D% EQU d (echo directory) else (echo file)
Code: Select all
@echo off
setlocal
set P=%1
for %%A in (%P%) do set X=%%~aA
set R=%X:~1,1%
if %R% EQU r (echo readonly) else (echo writeable)
endlocal
Code: Select all
SETLOCAL & SET P=%1 & FOR %%A IN (%P%) DO SET X=%%~aA & SET R=%X:~1,1% & IF %R% EQU r (echo readonly) ELSE (echo writeable) & ENDLOCAL
Code: Select all
E:\Users\sallyw\Downloads>sw3.bat test
E:\Users\sallyw\Downloads>SETLOCAL & SET P=test & FOR %A IN ((null)) DO SET
X=%~aA & SET R=~1,1R EQU r (echo readonly) ELSE (echo writeable) & ENDLOCAL
Code: Select all
@for %%A in ("%~1") do @echo %%~aA|find /i "r">nul&&(@echo readonly)||(@echo writeable)
Code: Select all
setlocal EnableDelayedExpansion & set G=%1 & for %%H in ( !G! ) do ( set I=%%~aH )
set J=%I:~1,1%
if %J% EQU r (echo readonly) else (echo writeable) & endlocal
Code: Select all
E:\Users\sallyw\Downloads>sw3.bat TEST
E:\Users\sallyw\Downloads>setlocal EnableDelayedExpansion & set G=TEST & for %H in (!G!) do (set I=%~aH )
E:\Users\sallyw\Downloads>(set I=dr------- )
E:\Users\sallyw\Downloads>set J=r
E:\Users\sallyw\Downloads>if r EQU r (echo readonly ) else (echo writeable ) & endlocal
readonly
cats_five wrote:It's complicated to explain clearly why it needs to be on one line, but it's to do with another program only being able to run a single line of DOS and only being able to pick up true or false as the outcome.
Code: Select all
IF EXIST "C:\path to some folder\subfolder\" echo is a folder
Code: Select all
H:\>cmd /C "IF EXIST "H:\temp\" (exit /b 0) else (exit /b 1)"
H:\>echo %errorlevel%
0
H:\>cmd /C "IF EXIST "H:\tempno\" (exit /b 0) else (exit /b 1)"
H:\>echo %errorlevel%
1