Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
BatMaster
- Posts: 28
- Joined: 22 Dec 2010 12:53
#1
Post
by BatMaster » 28 Jan 2013 15:31
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"
Last edited by
BatMaster on 28 Jan 2013 19:13, edited 1 time in total.
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#2
Post
by foxidrive » 28 Jan 2013 17:05
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.
-
BatMaster
- Posts: 28
- Joined: 22 Dec 2010 12:53
#3
Post
by BatMaster » 28 Jan 2013 20:02
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
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#4
Post
by foxidrive » 28 Jan 2013 23:21
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\
-
shirulkar
- Posts: 40
- Joined: 15 Jan 2013 23:53
#5
Post
by shirulkar » 28 Jan 2013 23:57
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
]
-
suresh_knv
- Posts: 5
- Joined: 21 Jan 2013 07:09
#6
Post
by suresh_knv » 29 Jan 2013 00:10
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