Computing.Net > Forums > Programming > batch: trim string error

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

batch: trim string error

Reply to Message Icon

Name: tuk
Date: May 27, 2008 at 09:24:02 Pacific
OS: vista
CPU/Ram: opteron 2.5gb
Product: dfi
Comment:

This seems like a whitespace error, but I cant find the answer,
note~ I need the path string format as described below for output to .txt file...


Format of path string 'stored' in %profileE%

"C:\Users\V1\AppData\Local\VirtualStore\Program Files (x86)\Activision\Call of Duty 4 - Modern Warfare\ "


Format of path string 'needed' in %profileE%

C:\Users\V1\AppData\Local\VirtualStore\Program Files (x86)\Activision\Call of Duty 4 - Modern Warfare
----------------


trim pathString code and error
----------------
IF NOT %profileE%==0 set profileE=%profileE:~0,-3%

echo on:\Activision\Call was unexpected at this time.
----------------


error code environment
----------------
SET profileE=0

FOR...(
SET foundPlayersFolder="%%~DPa"
IF...(
IF...(
IF...(SET profileE=!foundPlayersFolder!)
)
)
)

IF...(
IF NOT %profileE%==0 set profileE=%profileE:~1,-3%
)

Warning Batch Newbie:
Thanks For Being Patient!
Any Help Is Appreciated!



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: May 27, 2008 at 16:07:14 Pacific
Reply:

I'd like to see more of your code; echo is only referenced in the error and not your batch.


0

Response Number 2
Name: tuk
Date: May 27, 2008 at 16:45:31 Pacific
Reply:

I'v only shown the echo output for the line thats throws the error if thats what you mean?
actual message:
\Activision\Call was unexpected at this time.

My batch code is quite large, what code would you like to see?, the code I'v posted already shows the pathString(foundPlayersFolder) being initialised(using an actual PATH) all the parts of its journey to where it(profileE) fails on being trimmed for output
...do you want to see all this code un-edited? or something else?


ps
other pathStrings work without any problem, and these working pathStrings appear to have fewer or no whitespaces

Warning Batch Newbie:
Thanks For Being Patient!
Any Help Is Appreciated!


0

Response Number 3
Name: tuk
Date: May 27, 2008 at 18:25:47 Pacific
Reply:

this is basically the same as what I posted before, but in its entirety


FOR /f "tokens=* delims= " %%a IN ('dir/s/b/a-s \players') DO (
SET foundPlayersFolder="%%~DPa"
ECHO.
ECHO.

echo !foundPlayersFolder! | find "VirtualStore"
IF NOT errorlevel 1 (
ECHO.
ECHO.
----
echo. "WOULD YOU LIKE TO BACK-UP THIS PROFILE: ( Y )Yes BACK-UP ( N )NO CONTINUE SEARCHING ( Q )QUIT "


verify >nul
choice /N /C:YNQ
if errorlevel 1 set choice=Y
if errorlevel 2 set choice=N
if errorlevel 3 set choice=Q


IF /I !Choice!==Y (
REM Cls
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
echo SLOT E: !profileE!
echo SLOT F: !profileF!
echo SLOT G: !profileG!
echo SLOT H: !profileH!
ECHO.

ECHO ENTER A SLOT LETTER: E, F, G, H, TO OVERWRITE WITH NEW PROFILE LOCATION
ECHO.
ECHO WARNING!!! THIS WILL OVERWRITE ANY LOCATION DATA STORED IN THE SLOT SELECTED

verify >nul
choice /N /C:EFGH
if errorlevel 1 set choice=E
if errorlevel 2 set choice=F
if errorlevel 3 set choice=G
if errorlevel 4 set choice=H


IF /I !Choice!==E SET profileE=!foundPlayersFolder!
IF /I !Choice!==F SET profileF=!foundPlayersFolder!
IF /I !Choice!==G SET profileG=!foundPlayersFolder!
IF /I !Choice!==H SET profileH=!foundPlayersFolder!

echo SLOT E: !profileE!
echo SLOT F: !profileF!
echo SLOT G: !profileG!
echo SLOT H: !profileH!
)


IF /I !Choice!==N (ECHO NO)
IF /I !Choice!==Q (ECHO QUIT)

)
)


ECHO.
ECHO.
echo SLOT E: !profileE!
echo SLOT F: !profileF!
echo SLOT G: !profileG!
echo SLOT H: !profileH!

ECHO PRESS S TO SAVE THE ABOVE PROFILE SLOTS TO FILE OR M TO RETURN TO MAIN MENU
choice /N /C:SM
IF errorlevel 1 set choice=S
IF errorlevel 2 set choice=M


ECHO SAVE
IF /I !Choice!==S (
@pause
IF NOT %profileE%==0 set profileE=%profileE:~1,-3%
IF NOT %profileF%==0 set profileF=%profileF:~0,-3%
IF NOT %ProfileG%==0 set profileG=%profileG:~0,-3%
IF NOT %ProfileH%==0 set profileH=%profileH:~0,-3%
@pause

Warning Batch Newbie:
Thanks For Being Patient!
Any Help Is Appreciated!


0

Response Number 4
Name: Razor2.3
Date: May 27, 2008 at 19:05:58 Pacific
Reply:

ECHO SAVE
IF /I !Choice!==S (
@pause
IF NOT %profileE%==0 set profileE=%profileE:~1,-3%
IF NOT %profileF%==0 set profileF=%profileF:~0,-3%
IF NOT %ProfileG%==0 set profileG=%profileG:~0,-3%
IF NOT %ProfileH%==0 set profileH=%profileH:~0,-3%
@pause

Ah, your problem is either the lack of quotes, or the usage of % instead of !. Take your pick.


0

Response Number 5
Name: tuk
Date: May 28, 2008 at 05:20:19 Pacific
Reply:

1)
Why is your yellow box wider than mine lol,it puts my long com's on 2 lines and makes it harder for u guys to read

2)
Just to clarify, do you mean doing something like this:

IF NOT !profileE!==0 set profileE=%profileE:~1,-3%
or
IF NOT "%profileE%"==0 set profileE=%profileE:~1,-3%

Warning Batch Newbie:
Thanks For Being Patient!
Any Help Is Appreciated!


0

Related Posts

See More



Response Number 6
Name: tuk
Date: May 28, 2008 at 05:51:47 Pacific
Reply:

hmmmnn...maybe (x86) throws !profileE! and the whitespace after Program throws "%profileE%"

profileE
=
"C:\Users\V1\AppData\Local\VirtualStore\Program Files (x86)\Activision\Call of Duty 4 - Modern Warfare\"
-----

IF NOT !profileE!==0 set profileE=%profileE:~1,-3%
\Activision\Call was unexpected at this time.

IF NOT "%profileE%"==0 set profileE=%profileE:~1,-3%
Files was unexpected at this time.

I need the code to handle unknown pathStrings regardles of whitespaces, etc...other pathstrings using !profileE! or %profileE% work perfectly???
eg
"C:\Users\V1\Desktop\test\cod4 profile flagger\uac on\VirtualStore"

Warning Batch Newbie:
Thanks For Being Patient!
Any Help Is Appreciated!


0

Sponsored Link
Ads by Google
Reply to Message Icon

c++ - path question Exec Perl script from Ult...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: batch: trim string error

Batch Scripting-String Extraction www.computing.net/answers/programming/batch-scriptingstring-extraction/14471.html

Zero- length string Error www.computing.net/answers/programming/zero-length-string-error/11002.html

batch file string parsing www.computing.net/answers/programming/batch-file-string-parsing/16603.html