1.

Solve : go back in BAT?

Answer»

I am not sure how to search for this because i don't seem to get what i am looking for.

Let's say you run a BAT file in "FolderA\FolderB\FolderC\". In the BAT file i was to have it run a file in "FolderA". The issue is the drive letter can change or be a UNC path. Is there a way to specify "FolderA" without having a static drive letter?

Thanks for the help!I don't know if there is a way to do it. The way I have done it in the past is to first; think how many drive letters are possible, then make a line in the program for that letter.

Hope you can alter this to your needs.

Code: [Select]rem check whether file 'F:\FolderA\file' exist
If exist F:\FolderA\file goto goodf
If not exist F:\FolderA\file goto checkg

:checkg
rem check whether file 'G:\FolderA\file' exist
If exist G:\FolderA\file goto goodg
If not exist G:\FolderA\file goto checkh

:checkh
rem check whether file 'H:\FolderA\file' exist
If exist H:\FolderA\file goto goodh
If not exist H:\FolderA\file goto checke

:checke
rem check whether file 'E:\FolderA\file' exist
If exist E:\FolderA\file goto goode
If not exist E:\FolderA\file goto fail

:goodF
start F:\FolderA\file
goto END

:goodg
start G:\FolderA\file
goto end

:goodh
start H:\FolderA\file
goto end

:goode
start E:\FolderA\file
goto end

:fail
echo fail

:end

Someone will probably tell you a better way to do this but until then I hope this helps.

EDIT: This was made for a flashdrive. That is why the first drive letter F.do you mean that the batch file might be on a different drive?

Quote

do you mean that the batch file might be on a different drive?
Is that directed at my? If so then it could be but the program dose many things and the file that it runs is on the same drive so that you can transport it to any computer and still fined and run the program. It is based of the fact that when moving a flash drive from one pc to another it will have a different drive letter.C:\>type drive.bat
Code: [Select]@echo off

REM Use command line argument
REM drive.bat E



%1:
start %1:\FolderA\file
Output:

C:\> drive.bat E

E:\>HUH?
Is the objective to make this harder that it needs to be?
You can always execute a batch file in another directory on the same drive.
You can reference another file in another directory, even if the directory is not down in the current tree.
Example:
..\folder\file.txt
is a sideways reference to a file in a sister folder.
\folder\folder\file.txt
Is a reference from the root without SAYING which drive.
(It has to be the current dive.)
.\file.txt
means this folder.
Somewhere this is documented!

Quote from: Geek-9pm on September 24, 2009, 01:42:08 PM

Somewhere this is documented!



Wikipedia article title "Full stop"...

Quote
In Unix-like systems and Microsoft Windows, the dot character represents the working directory of the file system. TWO dots (..) represent the parent directory of the working directory.

Wikipedia article title "Path (computing)".

Quote
Two dots ("..") point upwards in the hierarchy, to indicate the parent directory; one dot (".") represents the current directory itself. Both can be components of a complex relative path

cd help

Code: [Select]C:\>cd /?
Displays the name of or CHANGES the current directory.

CHDIR [/D] [drive:][path]
CHDIR [..]
CD [/D] [drive:][path]
CD [..]
MSDN page titled "File Names, Paths, and Namespaces"

http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx


I like to keep my projects very organized and not have duplicate files. So this is a pretty big piece to have working. In this small project i simply needed to run "sleep.exe". It worked perfectly.

Thank you all for the input!

Code: [Select]"..\exes\sleep.exe" 3

-HoFLQuote from: TheHoFL on September 24, 2009, 04:01:16 PM
I like to keep my projects very organized and not have duplicate files. So this is a pretty big piece to have working. In this small project i simply needed to run "sleep.exe". It worked perfectly.


Code: [Select]"..\exes\sleep.exe" 3

HoFL,

I have no idea what you are talking about. Sleep.exe?

.. represents the current directory, up one. So "..\folder\name.bat" goes up one level, then looks in there for "folder" then GETS name.bat .Sleep.exe is a simply program that allows you to "pause" for a specified amount of seconds. It's like pause, but you don't have to hit a key to continue. It just starts after the amount if time specified. There is a sleep.com in this place:
http://dslgeek.com/dos/there watch my video on youtube --> http://www.youtube.com/watch?v=mqhemoOVfuU
than you know the code


Discussion

No Comment Found