Path recursively

I tried to find this on Google and didn’t actually find out, since the search results usually relate to other recursive topics. What I would like to know is if the folder is on the way, is it defined recursively (on Windows)? I want to create C: \ StandalonePrograms and add this to the path. It will contain a bunch of programming languages ​​and other programs that usually come from zip files. I want to know that if I add a program directory to it, I can name all the programs. For example, if I have C: \ StandalonePrograms \ SomeProgram, can I open a command prompt like someCommand and expect it to be launched from the C: \ StandalonePrograms \ SomeProgram \ bin folder? Or do I need to explicitly define C: \ StandalonePrograms \ SomeProgram \ bin in my path? If I can’t, are there any workarounds to achieve the situation I want?

+4
source share
2 answers

You need to specify each directory separately, the PATH mechanism does not go through subdirectories.

A workaround could be a directory full of batch files (something like) that run real tools with a full path

+6
source

Here is a workaround. Save this as "SetMyPath.bat" (or with a different name):

 @echo off set dir=%* setlocal EnableDelayedExpansion for /f "delims=" %%i in ('dir /s /ad /o:d /b "%dir:"=%"') do set path=%%i;!path! cmd 

(Here, "%dir:"=%" is only required so that you can exclude quotation marks around directories with a space in the names when calling this file. If you do not need this, it will be %1 instead).

This file takes one command line argument: directory. It will launch a new copy of cmd.exe , where the files under this directory will be available:

 C:\> mysqldump.exe File not found. C:\> SetMyPath.bat C:\Program Files\MySQL Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\> mysqldump.exe Usage: mysqldump [OPTIONS] database [tables] C:\> exit 

In this example, the first command shows that mysqldump.exe not in the path. After executing the batch file, a new cmd.exe is launched, where mysqldump.exe is available. When you finish working with it, exit will return the original copy of cmd.exe .

If there are two copies of the .exe file in different subdirectories, a copy will be launched in the last updated directory (due to /o:d ). In this example, assuming that the directory for the latest MySQL version was updated last, the most recent version of mysqldump.exe will be launched.

The batch file can be modified to ensure that the most recent copy of .exe is launched (ask me in the comments if you need it).

+2
source

Source: https://habr.com/ru/post/1347138/


All Articles