Change directory in path string?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Clueless in Seattle
Posts: 47
Joined: 01 Jul 2011 13:37

Change directory in path string?

#1 Post by Clueless in Seattle » 01 Nov 2013 07:52

Hi! I'm working on a batch file in MS-DOS 6.21.

I'm wondering if it's possible to write a batch file that will change the first directory name in a path string.

Here's an example of what I'm trying to do:

E:\PROJECT.DIR\DRAFT1\PROJECT.TXT

A:\PROJECT.BK1\DRAFT1\PROJECT.TXT

I've figured out how to change the Drive name, e.g. changing "E:\" to "A:". That was easy, because it's just the first three characters in the string.

But is it possible to search a string for the name of that first directory in the string and then change the three letter extension between the "dot" and the second "\"?

Will in Seattle
a.k.a. "Clueless"

Can a batch file in my old version of DOS pull off that trick? Or am I going to have to dig out my old version of BASIC for DOS and try to remember how to write programs with it?

Clueless in Seattle
Posts: 47
Joined: 01 Jul 2011 13:37

Re: Change directory in path string?

#2 Post by Clueless in Seattle » 01 Nov 2013 10:22

Since posting the above query I've played around with the macro language in my old DOS text editor, and it looks like I may be able to accomplish the task in the text editor and then pass the modified path string to my batch file from there.

I'll let you know if that works.

Will in Seattle
a.k.a. "Clueless"

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Change directory in path string?

#3 Post by foxidrive » 01 Nov 2013 18:40

You can use SED for dos to manipulate a string. Or Qbasic.

If you need help with them then reply again.

Clueless in Seattle
Posts: 47
Joined: 01 Jul 2011 13:37

Re: Change directory in path string?

#4 Post by Clueless in Seattle » 07 Nov 2013 14:22

Thanks foxidrive!

I'm an old guy and my memory is failing on me.

It's been a while since I wrote any serious batch files or BASIC programs, so I couldn't remember if there were any batch commands for manipulating strings. I'm afraid those old BASIC commands got mixed up in my memory with batch file commands.

As it turns out, it looks like the macro language built into my text editor will work for putting together modified path strings and then passing them on to a batch file.

So that's the approach I'm taking, and so far it's working out pretty well.

Thanks again,

Will in Seattle
a.k.a. "Clueless"

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Change directory in path string?

#5 Post by foxidrive » 07 Nov 2013 16:09

Clueless in Seattle wrote:As it turns out, it looks like the macro language built into my text editor will work for putting together modified path strings and then passing them on to a batch file.

So that's the approach I'm taking, and so far it's working out pretty well.


That's good. :)

rodrigolima
Posts: 21
Joined: 19 Jul 2013 11:35
Location: Brazil

Re: Change directory in path string?

#6 Post by rodrigolima » 29 Nov 2013 09:40

About your question Clueless in Seattle, I understood like this:

Try this:

Create variable called MyPath

set MyPath=E:\PROJECT.DIR\DRAFT1\PROJECT.TXT [ENTER]
echo %MyPath% [ENTER]
It shows "E:\PROJECT.DIR\DRAFT1\PROJECT.TXT" on the screen

After that, hit this

echo %MyPath:~1% [ENTER]
It shows ":\PROJECT.DIR\DRAFT1\PROJECT.TXT" on the screen

So, In my opinion just put letter A
echo A%MyPath:~1% [ENTER]
It shows "A:\PROJECT.DIR\DRAFT1\PROJECT.TXT" on the screen

See you

Post Reply