Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Directory names in batch files  (Read 2973 times)

0 Members and 1 Guest are viewing this topic.

JBHaywood

  • Guest
Directory names in batch files
« on: February 22, 2005, 07:53:44 PM »
I'm trying to run a backup program through a batch file command line; and what I'd like to do, if possible, is get the name of the folder the batch file is being run from and use that in the destination part of the command line for the backup program.

I'll try and illustrate to be more clear:
Batch file, backup.bat, is run from c:\work\stuff.
The command line for the backup program is: backup "SourceDirectory" "DestinationDirectory"
So I want "SourceDirectory" to be c:\work\stuff, and I want "DestinationDirectory" to be \\sever\otherDirectory\stuff.

I found the following code to retreive the name of the current directory:
:: get current directory
@SET cd=
@SET promp$=%prompt%
@PROMPT SET cd$Q$P
@CALL>%temp%.\setdir.bat
@
% do not delete this line %
@ECHO off
PROMPT %promp$%
FOR %%c IN (CALL DEL) DO %%c %temp%.\setdir.bat

This lets me use %cd% for the "SourceDirectory", but is there a way to strip out all but the actuall folder, in this case, "work", and append that the "DestinationDirectory", in this case, "\\sever\otherDirectory\"

I hope this makes sense any help would be greatly appreciated.