What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Little help with batch programming

Little help with batch programming
Author: Message:
Chancer
Senior Member
****

Avatar

Posts: 648
Reputation: 7
35 / Male / Flag
Joined: May 2005
Status: Away
O.P. Little help with batch programming
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?
02-03-2010 06:46 PM
Profile E-Mail PM Find Quote Report
prashker
Veteran Member
*****


Posts: 5109
Reputation: 104
– / Male / –
Joined: Mar 2005
Status: Away
RE: Little help with batch programming
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.

This post was edited on 02-03-2010 at 09:39 PM by prashker.
02-03-2010 09:32 PM
Profile PM Find Quote Report
Lou
Veteran Member
*****

Avatar

Posts: 2475
Reputation: 43
– / Male / Flag
Joined: Aug 2004
RE: Little help with batch programming
quote:
Originally posted by SonicSam
I don't remember { } brackets working
I don't see any anywhere :P.
[Image: msghelp.net.png]
The future holds bright things in it\\\'s path, but only time will tell what they are and where they come from.
Messenger Stuff Forums
02-03-2010 09:33 PM
Profile PM Web Find Quote Report
prashker
Veteran Member
*****


Posts: 5109
Reputation: 104
– / Male / –
Joined: Mar 2005
Status: Away
RE: Little help with batch programming
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.
02-03-2010 09:36 PM
Profile PM Find Quote Report
Chancer
Senior Member
****

Avatar

Posts: 648
Reputation: 7
35 / Male / Flag
Joined: May 2005
Status: Away
O.P. RE: Little help with batch programming
Just perfect. Thanks.
02-04-2010 12:05 AM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On