View unanswered posts | View active topics It is currently 18 Apr 2014 14:43



Post new topic Reply to topic  [ 3 posts ] 
Using a variable that's part of a filename to open that file 
Author Message

Joined: 25 Jun 2012 22:22
Posts: 2
Post Using a variable that's part of a filename to open that file
I'm not too smart in batch files.
If you have an idea that I can 'grow' with that would be fine!



Here's the basics of it:

I'll want to use a variable when typing into Run field this way:

C PLASTIC

Where typing PLASTIC would open PLASTIC.RTF

typing

C PLASTIC will open PLASTIC.COMMENT.RTF

---------------

The BATCH files I have only open text files.
e.g. Typing PLASTIC opens 'PLASTIC.RTF'

We'll call those the old text files I've had for years. The new text files will be the same names
except they'll have
.COMMENT
added to the name.

Another way to say that:
Their names will be names that I already have on other text files and with .COMMENT inserted into the name.

e.g PLASTIC.RTF gets a 'brother' and his file name is PLASTIC.COMMENTS.RTF


I'll want to use a variable when typing into Run field this way:

C PLASTIC

Where typing PLASTIC would open PLASTIC.RTF

typing

C PLASTIC will open PLASTIC.COMMENT.RTF





(1)
; Batch File Name 'PLASTIC.bat'
@echo off

start "D:\Program Files\Cwordpad\CWordPad.exe" "c:\Users\Acer1\Documents\PLASTIC.rtf"


25 Jun 2012 23:23
Profile

Joined: 10 Feb 2012 02:20
Posts: 3646
Post Re: Using a variable that's part of a filename to open that
I.Love.to.Use.DOS wrote:
I'll want to use a variable when typing into Run field this way:

C PLASTIC

Where typing PLASTIC would open PLASTIC.RTF

typing

C PLASTIC will open PLASTIC.COMMENT.RTF


(1)
; Batch File Name 'PLASTIC.bat'
@echo off

start "D:\Program Files\Cwordpad\CWordPad.exe" "c:\Users\Acer1\Documents\PLASTIC.rtf"



Call this a.bat and then you can type this (including the a)

a plastic
and it will open plastic.rtf

If you type

a b plastic
then it will open plastic.comment.rtf
b can be any character.



and if you change plastic to another word, say steel

a steel
it will open steel.rtf

and if you type
a b steel
then it will open steel.comment.rtf



Code:
@echo off
if  "%~2"=="" (start "D:\Program Files\Cwordpad\CWordPad.exe" "c:\Users\Acer1\Documents\%~1.rtf")
if not "%~2"=="" (start "D:\Program Files\Cwordpad\CWordPad.exe" "c:\Users\Acer1\Documents\%~2.comment.rtf"


26 Jun 2012 09:58
Profile

Joined: 25 Jun 2012 22:22
Posts: 2
Post Re: Using a variable that's part of a filename to open that
I just saw your post this morning. I'll have a good look at it
and try it but the idea looks good...
I hope it works. I'll let you know.
Thank you! Really appreciate the note.


30 Jun 2012 12:38
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 


Who is online

Users browsing this forum: Baidu [Spider], npocmaka_, pieh-ejdsch, Yahoo [Bot] and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Forum style by Vjacheslav Trushkin for Free Forums/DivisionCore.