Shoutbox

Little help with batch programming - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: Little help with batch programming (/showthread.php?tid=93752)

Little help with batch programming by Chancer on 02-03-2010 at 06:46 PM

This is my code:

code:
@echo off
FOR /f "tokens=*" %%G IN ('dir /b') DO (
    [my actions, no problem here]
)

It does my actions for each file in the bat file's folder.
The problem is, one of the arguments I need is the file's name without the extension. For example:
%%G is "My text file.txt" and I need to use the command -set name="My text file" .
So I changed -set name="%%G" to -set name="%%G:~0,-4%", which should ignore the last 4 characters (dot + extension), but it doesn't work.

Does anyone know how to solve this?
RE: Little help with batch programming by prashker on 02-03-2010 at 09:32 PM

code:
FOR /f "delims=" %%G IN ('dir /b') DO (
echo %%~nG
echo MY NAME IS SONICSAM AND I ROCK
echo %%~nG >> poop.txt
)
Notice the ~n, it removes the file extenson

There should be no need to set it to something else with this code, and I am not even sure setting it inside ()'s will even work...but the %%~n will allow you to do whatever you wanted with the original code.
RE: Little help with batch programming by Lou on 02-03-2010 at 09:33 PM

quote:
Originally posted by SonicSam
I don't remember { } brackets working
I don't see any anywhere :P.
RE: Little help with batch programming by prashker on 02-03-2010 at 09:36 PM

quote:
Originally posted by Lou
quote:
Originally posted by SonicSam
I don't remember { } brackets working
I don't see any anywhere :P.
Odd, my eyes deceived me. Edited post.
RE: Little help with batch programming by Chancer on 02-04-2010 at 12:05 AM

Just perfect. Thanks.