Batch code to print each path entry in a new row? [duplicate] - batch-file

This question already has answers here:
'Pretty print' windows %PATH% variable - how to split on ';' in CMD shell
(12 answers)
Closed 7 years ago.
Can any share a batch script that prints each batch entry in a new row?
eg - if Path = C:\Python27;C:\Python27\Scripts
Then it shall get printed as
C:\Python27
C:\Python27\Scripts

I have a VBscript that does this:
Set oShell = CreateObject( "WScript.Shell" )
pathList = oShell.ExpandEnvironmentStrings("%PATH%")
dirs = Split(pathList, ";", -1, 1)
For i = 0 to UBound(dirs)
WScript.Echo dirs(i)
Next
Save it as e.g. list_path.vbs and you can use it just like any other batch file.
If you can't run it by entering list_path you need to adjust the value of PATH_EXT in order to include .vbs (but I think that is the default in modern Windows versions - I can't remember having to adjust that)

Related

How do I make a self locating batch file [duplicate]

This question already has answers here:
Get current batchfile directory
(4 answers)
Closed 3 years ago.
So basicly I want to make a batch file that can execute other files, while learing its own location on execution.
It should then use it own path as a reference to the other files.
How should I go about coding that or are there any guides for exactly that?
Thanks in advance!
The batch file name as entered via command line is stored in %0. Using file expander to get other parts. You can put the following code into a batch file and try it out:
REM print batch filename as user entered
echo %0
REM print full file name: d - drive, p - path, f - filename
echo %~dpf0
REM print path only
echo %~dp0
The current directory is stored in %CD%, in case you need it.

Update PATH without altering the env variables already there [duplicate]

This question already has answers here:
Append a directory to PATH Environment Variable in Windows
(3 answers)
Why are other folder paths also added to system PATH with SetX and not only the specified folder path?
(1 answer)
How to search and replace a string in environment variable PATH?
(1 answer)
Adding the current directory to Windows path permanently
(2 answers)
What is the reason for "X is not recognized as an internal or external command, operable program or batch file"?
(4 answers)
Closed 3 years ago.
My PATH has few entries like %SystemRoot%, %USERPROFILE%/... etc which are pointing to another env variable. But when I update the PATH with command line, it replaces those env entries with actual value like e.g. below
Earlier Entry : %SystemRoot%;%USERPROFILE%\AppData
SETX MY_ENV "C:\MyData"
SETX PATH %MY_ENV%;%PATH%
Path Value : C:\MyData;C:\Windows;C:\USers\UserName\AppData
But, I am looking for a solution which can be run directly as cmd line por through Batch programming that will set my Path as below
%MY_ENV%;%%SystemRoot%;%USERPROFILE%\AppData
This is not the Path variable meant for logged in user but is the system path variable.

Append a Registry Key via Batch File [duplicate]

This question already has answers here:
Adding a directory to the PATH environment variable in Windows
(21 answers)
Adding environment variable from command prompt / batch file
(2 answers)
How to set PATH environment variable in batch file only once on Windows?
(2 answers)
Why are other folder paths also added to system PATH with SetX and not only the specified folder path?
(1 answer)
Adding the current directory to Windows path permanently
(2 answers)
Closed 4 years ago.
Is there a way to append a Registry key with a batch file? To be clear, I don't want to replace the key, I want to add to it.
Example:
Key Location: HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
Change: C:\Windows;C:\Java
To: C:\Windows;C:\Java;C:\Program Files (x86)\CFLAT
It's a REG_EXPAND_SZ, so [~] won't work, unless I'm doing it wrong.
https://msdn.microsoft.com/en-us/library/aa371168(VS.85).aspx
Save this to something.reg. Execute this with double click and you will set changes. This is maybe overwriting but I think this is better idea.
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v C:\Windows;C:\Java;C:\Program Files (x86)\CFLAT /t REG_SZ /f

Create cmd command with parameters in batch [duplicate]

This question already has answers here:
How can I pass arguments to a batch file?
(20 answers)
Closed 6 years ago.
I want to create a cmd command by writing a batchfile and put it into "system32" to call it in the cmd console by its name. Is there a way to expect parameters in the batch file:
Write in cmd:
fake-command Test
And then work with the string "Test" in the batch file?
Use %1 to access the first argument, %2 for the second, etc.

Copy from variable to variable [duplicate]

This question already has answers here:
Assign command output to variable in batch file [duplicate]
(5 answers)
Closed 6 years ago.
For my batch file I need to do a few different things...I have completed steps 1-3
1) Perform a dir search and save the result of that search in a variable
2) Set the destination path as a variable
3) Copy the source file to the destination path
My code so far :
#echo off
cls
cd /d D:\Downloads\Videos
set "flshvid=&dir *flash*.mkv /s /b"
set "flshdir=O:\Aayush\Videos\TV Shows\The Flash\Season 3"
xcopy %flshvid% %flshdir%
Why doesn't this code work?
Any help is appreciated. Thanks in advance!
Environment variables may not start with a numeric because %n where n is 0..9 refers to the serial parameter number provided to the routine.
replace 1 and 2 with variable names that do not start with a numeric

Resources