Computing.Net > Forums > Disk Operating System > Batch File

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 File

Reply to Message Icon

Name: Stefan Mai
Date: July 10, 2001 at 16:03:08 Pacific
Comment:

I have a simple problem. What I need to do is remove the extension from a variable such as %a (contains a filename) and put this into %b.

For example:
When %a is abc.jpg %b is abc

Thanks In Advance!
Stefan



Sponsored Link
Ads by Google

Response Number 1
Name: kev100
Date: July 10, 2001 at 20:38:20 Pacific
Reply:


This is so cool! I just guessed, but it works. Little things like this is why I like DOS so much....even in our GUI world.

Just use a wildcard. Example...

rename *.doc *.txt

will change the every .doc extension of the files IN THE CURRENT DIRECTORY to a .txt extension.

LIKEWISE

rename *.doc *

will simply remove the .doc extension of every file (which has a .doc extension).

HOWEVER, be VERY, VERY careful not to remove it from files which you DO want to have it. This is a very unforgiving command. MAKE BACKUP COPIES OF THE FILES YOU PLAN TO MANIPULATE.


0

Response Number 2
Name: Secret_Doom
Date: July 11, 2001 at 21:29:33 Pacific
Reply:

Here goes a more secure way:
(I'm using %a% and %b%)

@echo off
set b=
if "%extout%"=="1" goto parse
set extout=1
echo ; |choice /c;%a%; %0;>out.bat
out.bat
:parse
IF "%1"=="[" SHIFT
IF "%1"=="]?" goto end
IF "%1"=="." goto end
IF NOT "%B%"=="" SET B=%B%%1
IF "%B%"=="" SET B=%1
SHIFT
GOTO parse
:end
set extout=
if exist out.bat del out.bat

That's it. That weren't made by me. Laurence Soucy did it (just a little different) and I have adapted it to your case

-- Secret_Doom --


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


dos Adding SoundBlaster 16 to...



Post Locked

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


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Batch File

Help!! Batch File www.computing.net/answers/dos/help-batch-file/13525.html

Batch files - - Mapping network drive www.computing.net/answers/dos/batch-files-mapping-network-drive/3809.html

Pause batch file www.computing.net/answers/dos/pause-batch-file/2810.html