1.

Solve : compair a black space to a string?

Answer»

Hi,

As the title saids really....


I have a varible that sometimes gets set to nothing (if no file present) and I'd like to change the varible to "No File Avaiable" if the VARIABLE is blank.

example,

REM Searching for latest PRICE file and setting varaible's

set directory="t:\price_updates"
cd /d %directory%

FOR /F %%i IN ('dir /b /a-d /od') DO (
set lastfileP=%%i
set newdateP=%%~ti
)

if /i %Lastfile%==" " (set lastfile="No UPDATE Avaiable")

echo %lastfile%

but my if statment doesn't work.

any ideas??



Try this
if /i "%Lastfile%"==" " (set lastfile="No Update Available")

But if the value is truly blank, you might need to test this way
if /i "%Lastfile%"=="" (set lastfile="No Update Available")

GrahamHi,

Thanks for the suggestion.

I've tried both ways but sadly neither has worked.


The variable "lastfileP" is still echoing as a blank.


ggrrrrrr!!!

no wait.......



my bad,

if /i "%Lastfile%"=="" (set lastfile="No Update Available")


does work.

nice. cheers dude.

Quote from: blastman on February 21, 2008, 02:26:53 AM

if /i %Lastfile%==" "

That tests if the string Lastfile is one space, not an empty stringQuote from: Dias de verano on February 21, 2008, 04:48:05 AM
Quote from: blastman on February 21, 2008, 02:26:53 AM
if /i %Lastfile%==" "

That tests if the string Lastfile is one space, not an empty string

would the other example work for an empty string then??

Quote from: blastman on February 21, 2008, 05:18:27 AM
Quote from: Dias de verano on February 21, 2008, 04:48:05 AM
Quote from: blastman on February 21, 2008, 02:26:53 AM
if /i %Lastfile%==" "

That tests if the string Lastfile is one space, not an empty string

would the other example work for an empty string then??



In an IF test, you need to enclose BOTH strings in quotes

if /i "%Lastfile%"=="" (set lastfile="No Update Avaiable")

and available has a letter 'l'.
here try to set it up like dis
set /p Lastfile=What is the name of the file u are LOOKING for?
asks for ^ the name of the file

if not %Lastfile% exists set %Lastfile%="No Update Avaible"(may not have proper spelling)
echo %Lastfile%
^looks for the specifed file and the if the file doesnt exist the it says "No Update Avaible"Quote from: macdad- on February 21, 2008, 05:52:36 AM
here try to set it up like dis
set /p Lastfile=What is the name of the file u are looking for?
asks for ^ the name of the file

if not %Lastfile% exists set %Lastfile%="No Update Avaible"(may not have proper spelling)
echo %Lastfile%
^looks for the specifed file and the if the file doesnt exist the it says "No Update Avaible"

I am afraid this is nonsense
Dias de verano,

You sir, are a star!!

thanks for all your help over the last few days.

Couldn't of DONE it without you.

Cheers.


Discussion

No Comment Found