Will the FOR LOOP work on Windows 2003 Server

October 21, 2010 at 07:06:55
Specs: Windows 2003 server SP2, Xeon 3 gig
Hi All, I was wondering if the following would run on a windows 2003 server box. Basically a colleague told me that certain CMD line commands don't run on other versions of Windows.
Thank you. Lee

@echo off & setlocal enabledelayedexpansion
set counter=0

for /f %%a in ('dir /b') do (
set line=%%~ta
set filename=%%a
set line=!line:~0,10!
if "!line!" == "%date%" (
if !filename:~-4! == .exe (
if "!filename:~0,4!" == "sdat" (
set /a counter +=1
if !counter! geq 2 (
echo There are 2 or more SDAT's with todays date, please copy latest file manually. & pause & goto :EOF
) else (
set usefile=!filename!
)
)
)
)
cls
)

echo !usefile! is latest file.


See More: Will the FOR LOOP work on Windows 2003 Server

Report •

#1
October 21, 2010 at 07:46:55
Sorry, I should explain what it does. It will check the directory to find an exe file with today's date beginning with the letters 'SDAT', and then create a variable with that filename.

Cheers


Report •

#2
October 21, 2010 at 07:47:29
Basically a colleague told me that certain CMD line commands don't run on other versions of Windows.
Such as?

How To Ask Questions The Smart Way


Report •

#3
October 21, 2010 at 07:56:46
There is nothing in your batch not supported under Windows Server 2003, just verify the %date% format to be sure its layout is compatible with %%~ta (where however the time must be sripped away).

By the way why do you not use the %%~na for plain filename and %%~xa for the extension (that includes the dot)?


Report •

Related Solutions

#4
October 21, 2010 at 09:05:18
Thank you IVO, I will incorporate %%~na and %%~xa. I just didn't even think to use them!

Hi Razor2.3, I was not sure myself, but my colleague told me that he had tried %date:~0,2% etc... to break down the date but it didnt work on that server. So he had to use a for loop with 3 tokens to get the date stripped into ddmmyyyy.

I was going to test this tomorrow night, I really wanted to make sure about the commands first becauswe I didn't want any errors.

Thanks guys.
Lee


Report •

Ask Question