Page 1 of 1
Variables inside a path?
Posted: 28 Jan 2013 15:31
by BatMaster
Hey guys!
I was just working on something when i wondered if it was possible to put variables inside a directory like this
where %var% is the name of a folder inside \directory\
Its to help cut down on code when i have multiple instances of the same thing but with different modifications in each one
Ive tried but it, but with no success
Thanks in advance.
.BatMasteredit: "file location directory" to "path"
Re: Variables inside a files location directory?
Posted: 28 Jan 2013 17:05
by foxidrive
Yes, you can use variables in a path.
There are the usual restrictions for long pathname elements like spaces and & and so it should be double quoted.
If you explain your task then we can provide some sample code.
Re: Variables inside a path?
Posted: 28 Jan 2013 20:02
by BatMaster
I want to have multiple instances of Minecraft to choose from and each one is stored in its own folder
Code: Select all
/minecrafts/1/.minecraft/
/minecrafts/2/.minecraft/
/minecrafts/3/.minecraft/
etc.
I want to be able to use the path /minecrafts/%var%/.minecraft/
to choose the different ones
Re: Variables inside a path?
Posted: 28 Jan 2013 23:21
by foxidrive
BatMaster wrote:I want to have multiple instances of Minecraft to choose from and each one is stored in its own folder
Code: Select all
/minecrafts/1/.minecraft/
/minecrafts/2/.minecraft/
/minecrafts/3/.minecraft/
etc.
I want to be able to use the path /minecrafts/%var%/.minecraft/
to choose the different ones
You didn't explain what you want to do.
You can use an input statement to get the number:
Code: Select all
@echo off
set "var="
set /p "var=Enter the minecraft number (1-9): "
if not defined var goto :EOF
copy /b "\minecrafts\%var%\.minecraft\*.*" "\my new minecraft\
Re: Variables inside a path?
Posted: 28 Jan 2013 23:57
by shirulkar
Hi,
My code will access all the instances which are stored in different folders. In my code "minecrafts" folder is parent folder and i have following path
/minecrafts/1/minecraft/log.txt
/minecrafts/2/minecraft/log1.txt
/minecrafts/3/minecraft/log2.txt
output from this code is
log.txt
log1.txt
log2.txt
so i cane able to hit all the file.
[code][@ECHO OFF
FOR /F "tokens=* delims=" %%G IN ('DIR /d /b /s /a-d minecrafts') DO CALL :FileName "%%~nxG"
Exit /b
:FileName
set str1=%~1
ECHo %str1%
Exit /b
]
Re: Variables inside a path?
Posted: 29 Jan 2013 00:10
by suresh_knv
hi,
May be this code may be helpful which uses a variable to access the path
@echo off
set /a num=1
cd "minecrafts\%num%\abc"
pause
set /a num=1+1
cd "minecrafts\%num%\abc"
here i am using num variable in the path this way we can acess the folders