i need a batch to find the 1st level of dir name and the 2nd

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
nnnmmm
Posts: 162
Joined: 26 Aug 2017 06:11

i need a batch to find the 1st level of dir name and the 2nd

#1 Post by nnnmmm » 01 Oct 2022 07:51

Code: Select all

path = "M:\11 11\22 22\33 33\44 44\A B C D.TXT"
definition :
1st level dir name is 11 11
2nd level dir name is 22 22

i need a batch to find the 1st level of dir name and the 2nd

ShadowThief
Expert
Posts: 1166
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: i need a batch to find the 1st level of dir name and the 2nd

#2 Post by ShadowThief » 01 Oct 2022 09:47

%PATH% is already a system variable, so you should call it something else. After that, you can simply delimit the string on \ and grab the second and third tokens.

Code: Select all

@echo off
set "full_path=M:\11 11\22 22\33 33\44 44\A B C D.txt"

for /f "tokens=2,3 delims=\" %%A in ("%full_path%") do (
	set "top_level=%%A"
	set "second_level=%%B"
)

echo Top level directory: %top_level%
echo Next level directory: %second_level%

nnnmmm
Posts: 162
Joined: 26 Aug 2017 06:11

Re: i need a batch to find the 1st level of dir name and the 2nd

#3 Post by nnnmmm » 01 Oct 2022 22:15

thanks for your help

i needed this code to put a little bit of intelligence to find games
it will reduce a lot of labors to find games,
i can clcik anywhere, any sub dirs or any files, it will find a game to run

Post Reply