Copy from variable to variable [duplicate] - batch-file

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

Related

Using the %%var%% with batch file [duplicate]

This question already has answers here:
windows batch command nested variable
(2 answers)
Arrays, linked lists and other data structures in cmd.exe (batch) script
(11 answers)
Closed last year.
CALL SET %PROJECT%_VERSION=1_7_0
echo %%PROJECT%_VERSION%
The result will be %PROJECT.
How can I let it to 1_7_0
Using delayedexpansion makes life easier for these types of scenarios.. You do not need to get the number of % 100% either side of the variables and no need to use call:
#echo off
setlocal enabledelayedexpansion
set "PROJECT=Projectname"
SET "%PROJECT%_VERSION=1_7_0"
echo !%PROJECT%_VERSION!

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.

Batch File How to echo Series Variable's Value in a loop [duplicate]

This question already has answers here:
Arrays, linked lists and other data structures in cmd.exe (batch) script
(11 answers)
Batch Script - How to get variable value using a different variable that has the variable name stored
(1 answer)
using a DelayedExpansion index variable for an array within an IF statement fails
(2 answers)
Closed 3 years ago.
I have a series variable named Installer1 to Installer18
I am trying to install all installer 18 using a loop, so far I have this code to check if I am getting the value but the real value of variable is not reflecting, I believe there is missing on my code but I have tried my best but it is not enough. Thank you in advance
Here is what I have so far
I've got this result, I want to echo the value of the variable i declared on top of my loop but I got the variable name instead of value. I am not sure how to concatenate string and script will look it as a variable name.
I tried below code:
And I got this result:
Use array , Please try this.
#echo off
setlocal enabledelayedexpansion
SET var[0]=A
SET var[1]=foo bar
SET var[2]=123
for %%a in (0,1,2) do (
echo !var[%%a]!
)
echo Get one of the variables directly: %var[1]%

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

Removing second extension from file name [duplicate]

This question already has answers here:
Replace old file with new file
(3 answers)
Closed 6 years ago.
I have files like below:
Filename.txt
Filename.txt.new
Filename2.txt
Filename2.txt.new
I want to remove the "new" keyword for the files ending with "new"
also when we do this, existing file will also have same name, so i want to overwrite the same with the contents of the files ending with "new"
Sadly this is a case where ren *.foo *.bar won't work, but we can do it with a simple loop:
for %x in (*.new) do move /y "%x" "%~nx"
This simply loops over all files that have a .new extension (you could also do the same only for *.txt.new) and renames them. %~nx removes the extension from the name, in this case the .new.
When using this in a batch file you have to double the % signs:
for %%x in (*.new) do move /y "%%x" "%%~nx"

Resources