- Set path from command line
- How to set path from command line?
- Add directory to system path environment variable:
- Default option is not allowed more than ‘2’ time(s)
- Как отредактировать PATH в Windows 7, 8 и Windows 10?
- Что такое PATH система Windows?
- Как добавить папку в PATH?
- Path в операционной системе Windows 7 и Windows 8
- Path в операционной системе Windows 10
- Split-Path
- Syntax
- Description
- Examples
- Example 1: Get the qualifier of a path
- Example 2: Display file names
- Example 3: Get the parent container
- Example 4: Determines whether a path is absolute
- Example 5: Change location to a specified path
- Example 6: Split a path by using the pipeline
- Parameters
- Inputs
- Outputs
- Notes
Set path from command line
Users can run an executable from windows command prompt either by giving the absolute path of the file or just by the executable file name. In the latter case, Windows searches for the executable in a list of folders which is configured in environment variables. These environment variables are as below.
1. System path
2. User path
The values of these variables can be checked in system properties( Run sysdm.cpl from Run or computer properties). Initially user specific path environment variable will be empty. Users can add paths of the directories having executables to this variable. Administrators can modify the system path environment variable also.
How to set path from command line?
In Vista, Windows 7 and Windows 8 we can set path from command line using ‘setx’ command.
For example, to add c:\dir1\dir2 to the path variable, we can run the below command.
Alternative way is to use Windows resource kit tools ‘pathman.exe‘. Using this command we can even remove a directory from path variable. See download windows resource kit tools. This works for Windows 7 also.
Add directory to system path environment variable:
Open administrator command prompt
Run the below command
Remove path from system path environment variable:
Run the below command from elevated command prompt
Setting user path environment variable
For user environment varlables, admin privileges are not required. We can run the below command to add a directory to user path environment variable.
To remove a directory from user path, you can run the below command.
Default option is not allowed more than ‘2’ time(s)
You get this error if you have not enclosed ‘path’ in double quotes. See the below example for setting the path of firefox.
Now if you move %path% to be in the double quotes
Could a context entry be created for folders, perhaps an extended one… to add to path?
what about a multi-verb option, like copy as path?
hi, when i use setx at an administrator command line, it creates a USER variable, NOT the SYSTEM variable. What am i doing wrong? How do i change the SYSTEM path at command prompt? -thx
Johny Why
Answer: Try add the parameter /M
Hi, is there a way I can add an extra variable instead on deleting the currently one and put a new Variable on the Path.
I used the command setx /M “c:\Options”, and what it does is delete the current one and then puts that one there, all I want is to add the new variable to the current one. -thx
Nuno, pathman described above does exactly that. You can download the resource tools kit and get it.
setx path “%path%;C:\yourFolder”
To set path for java & javac, can I add the paths to PATH or do I need to create the environment variable JAVA_HOME. I don’t have this defined, but windows does not seem to be able to find java binaries on my system.
You can directly add the folder to PATH. No need to define JAVA_HOME. However, adding JAVA_HOME separately avoids cluttering and helps to easily understand what is added.
hello, can someone plz explain this result? After setting path, it did not change. This was run from an Administrator command-line:
C:\Windows\system32>setx path “C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\ProgramData\chocolatey\bin;D:\Program Files (x86)\Microsoft VS Code\bin”
SUCCESS: Specified value was saved.
C:\Windows\system32>path
PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\ProgramData\chocolatey\bin;D:\Program Files (x86)\Microsoft VS Code\bin;D:\Program Files (x86)\metapad36;D:\Program Files (x86)\metapad36″ /M
Why won’t this work?
SET EPO = D:\Program Files (x86)\McAfee\ePolicy Orchestrator
PATH = %PATH%;%EPO%\jre\bin;%EPO%\apache2\bin
In windows 10 set path %path%; not working. it’s work like :
setx “%path%;C:\Program Files\CodeBlocks\MinGW\bin”
By unfortunately I deleted my system default path. How could I able to find my system path?
Unfortunately I deleted several files with unremembered path names. This article was useful
The following used to work for me when I am in MSDOS environment. Lately I get error messages such as INCLUDE not found. Why is this so?
Used to work
SET PLL =c:\CL5\PLL
SET PLT =c:\CL5\PLL
SET INCLUDE =c:\CL5\INCLUDE
SET PRG =c:\IMS\PRG
SET LIB =c:\CL5\LIB
SET OBJ =c:\CL5\OBJ
PATH =c:\IMS\EXE;\CL5\BIN;\CL5\NG;\CL5\PLL
pathman is one of many tools of the Windows Server 2003 Resource Kit Tools
Note: The Windows Server 2003 Resource Kit Tools are not supported on 64-bit platforms.
Huh.
When I did that on Windows 10 v1903, using setx, it replaced the USER scope paths with the SYSTEM scope paths.
Now I’m not sure what was in the old user path.
So, uh… Be careful out there.
And if anyone has a solution how to avoid that, please let me know
Thanks
Как отредактировать PATH в Windows 7, 8 и Windows 10?
Как запустить программу из командной строки не переходя каждый раз в папку с программой?! Как запускать сторонние программы так, как, например, программу IPCONFIG, которая не требует перехода в папку?
Что такое PATH система Windows?
Если вы скачали программу командной строки, например ADB (Android Debuggin Bridge), то вы не сможете запустить ее просто вписав adb в командной строке, как вы всегда поступали с системными командами Windows (IPCONFIG, NETSTAT и т.п.). Вместо этого вы должны будете указать командную строку содержащую полный путь к exe-файлу.
Это достаточно сложно писать в командной строке без ошибок, тем более, если вам приходится делать это достаточно часто.
PATH система Windows сообщает вашей операционной системе каталоги, в которых следует искать исполняемые файлы. Например ранее упоминаемая программа ipconfig.exe расположена в каталоге C:\Windows\System32, который в свою очередь уже добавлен в PATH Windows. При вводе команды ipconfig система обыщет все папки из PATH на наличие файла ipconfig.exe и запустит его выполнение.
Если вы хотите то же удобство с программой (в нашем примере это ADB), то приложение ADB необходимо добавить в PATH Windows и после этого для запуска достаточно будет вписать в командную строку:
Больше ничего впечатывать не придется.
Как добавить папку в PATH?
В Windows 7, 8 и Windows 10 попасть в настройки PATH можно так: Панель управления / Система / Дополнительные переменные среды.
Далее перейти в «Переменные среды».
В окне «Переменные среды» обратите внимание на переменную с именем Path. Выберите ее и нажмите «Изменить..»
Дальнейшие действия одинаковы в Windows 7 и 8, но иные, облегченные, в Windows 10.
Path в операционной системе Windows 7 и Windows 8
В этих системах переменная Path является не более, чем длинной строкой текста с адресами каталогов системы. В этот текст мы добавим каталог и с нашей программой ADB.
Для того, чтобы добавить запись с путем к исполняемому файлу в Windows 7 и 8 к тексту нужно добавить путь, которому предшествует точка с запятой, разделяющая различные записи. Например так:
Добавлять такой путь в текст path нужно только в конец строки.
После ввода нажмите ОК. Все, мы добавили каталог в patch Windows 7 и 8.
Path в операционной системе Windows 10
В операционной системе Windows 10 этот процесс проще и менее запутанный. После нажатия кнопки «Изменить…» откроется новое диалоговое окно с расположенными в отдельных строках путях path.
Это улучшение позволяет проще и нагляднее видеть имеющиеся пути path и облегчает добавить новые пути.
Для добавления нового пути в переменную path Windows 10 нужно нажать «Новый», добавить путь C:\Android\platform-tools и нажать ОК.
Новая запись появится в низу списка.
Теперь запуск Android Debug Bridge доступен из любого раздела командной строкой без ввода полного пути к исполняемому файлу.
Split-Path
Returns the specified part of a path.
Syntax
Description
The Split-Path cmdlet returns only the specified part of a path, such as the parent folder, a subfolder, or a file name. It can also get items that are referenced by the split path and tell whether the path is relative or absolute.
You can use this cmdlet to get or submit only a selected part of a path.
Examples
Example 1: Get the qualifier of a path
This command returns only the qualifier of the path. The qualifier is the drive.
Example 2: Display file names
This command displays the files that are referenced by the split path. Because this path is split to the last item, also known as the leaf, the command displays only the file names.
The Resolve parameter tells Split-Path to display the items that the split path references, instead of displaying the split path.
Like all Split-Path commands, this command returns strings. It does not return FileInfo objects that represent the files.
Example 3: Get the parent container
This command returns only the parent containers of the path. Because it does not include any parameters to specify the split, Split-Path uses the split location default, which is Parent.
Example 4: Determines whether a path is absolute
This command determines whether the path is relative or absolute. In this case, because the path is relative to the current folder, which is represented by a dot ( . ), it returns $False .
Example 5: Change location to a specified path
This command changes your location to the folder that contains the PowerShell profile.
The command in parentheses uses Split-Path to return only the parent of the path stored in the built-in $Profile variable. The Parent parameter is the default split location parameter. Therefore, you can omit it from the command. The parentheses direct PowerShell to run the command first. This is a useful way to move to a folder that has a long path name.
Example 6: Split a path by using the pipeline
This command uses a pipeline operator ( | ) to send a path to Split-Path . The path is enclosed in quotation marks to indicate that it is a single token.
Parameters
This parameter is not supported by any providers installed with PowerShell. To impersonate another user, or elevate your credentials when running this cmdlet, use Invoke-Command.
Type: | PSCredential |
Position: | Named |
Default value: | None |
Accept pipeline input: | True |
Accept wildcard characters: | False |
Indicates that this cmdlet returns only the extension of the leaf. For example, in the path C:\Test\Logs\Pass1.log , it returns only .log .
This parameter was introduced in PowerShell 6.0.
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Accept pipeline input: | True |
Accept wildcard characters: | False |
Indicates that this cmdlet returns $True if the path is absolute and $False if it is relative. An absolute path has a length greater than zero and does not use a dot ( . ) to indicate the current path.
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Indicates that this cmdlet returns only the last item or container in the path. For example, in the path C:\Test\Logs\Pass1.log , it returns only Pass1.log.
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Accept pipeline input: | True |
Accept wildcard characters: | False |
Indicates that this cmdlet returns only base name of the leaf. For example, in the path C:\Test\Logs\Pass1.log , it returns only Pass1 .
This parameter was introduced in PowerShell 6.0.
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Accept pipeline input: | True |
Accept wildcard characters: | False |
Specifies the paths to be split. Unlike Path, the value of LiteralPath is used exactly as it is typed. No characters are interpreted as wildcard characters. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell PowerShell not to interpret any characters as escape sequences.
Type: | String [ ] |
Aliases: | PSPath, LP |
Position: | Named |
Default value: | None |
Accept pipeline input: | True |
Accept wildcard characters: | False |
Indicates that this cmdlet returns the path without the qualifier. For the FileSystem or registry providers, the qualifier is the drive of the provider path, such as C: or HKCU: . For example, in the path C:\Test\Logs\Pass1.log , it returns only \Test\Logs\Pass1.log .
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Accept pipeline input: | True |
Accept wildcard characters: | False |
Indicates that this cmdlet returns only the parent containers of the item or of the container specified by the path. For example, in the path C:\Test\Logs\Pass1.log , it returns C:\Test\Logs . The Parent parameter is the default split location parameter.
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Accept pipeline input: | True |
Accept wildcard characters: | False |
Specifies the paths to be split. Wildcard characters are permitted. If the path includes spaces, enclose it in quotation marks. You can also pipe a path to this cmdlet.
Type: | String [ ] |
Position: | 0 |
Default value: | None |
Accept pipeline input: | True |
Accept wildcard characters: | True |
Indicates that this cmdlet returns only the qualifier of the specified path. For the FileSystem or registry providers, the qualifier is the drive of the provider path, such as C: or HKCU: .
Type: | SwitchParameter |
Position: | 1 |
Default value: | None |
Accept pipeline input: | True |
Accept wildcard characters: | False |
Indicates that this cmdlet displays the items that are referenced by the resulting split path instead of displaying the path elements.
Type: | SwitchParameter |
Position: | Named |
Default value: | None |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Inputs
You can pipe a string that contains a path to this cmdlet.
Outputs
System.String, System.Boolean
Split-Path returns text strings. When you specify the Resolve parameter, Split-Path returns a string that describes the location of the items; it does not return objects that represent the items, such as a FileInfo or RegistryKey object.
When you specify the IsAbsolute parameter, Split-Path returns a Boolean value.
Notes
The split location parameters (Qualifier, Parent, Extension, Leaf, LeafBase, and NoQualifier) are exclusive. You can use only one in each command.
The cmdlets that contain the Path noun (the Path cmdlets) work with path names and return the names in a concise format that all PowerShell providers can interpret. They are designed for use in programs and scripts where you want to display all or part of a path name in a particular format. Use them in the way that you would use Dirname, Normpath, Realpath, Join, or other path manipulators.
You can use the Path cmdlets together with several providers. These include the FileSystem, Registry, and Certificate providers.
Split-Path is designed to work with the data exposed by any provider. To list the providers available in your session, type Get-PSProvider . For more information, see about_Providers.