Solved Set filename as variable then split it

May 24, 2020 at 05:23:13
Specs: Windows 7
Hi.
I'm attempting to take the filename, split it using the delimiter comma and then set the output as 2 variables.
This is what I have so far:
SET FILEN=%~n0
FOR /f "tokens=1,2 delims=," %%a IN ("%FILEN%") do SET %%a&SET %%b

Unfortunately it doesn't work. Can anyone shine a light as to where I am going wrong.


See More: Set filename as variable then split it

Reply ↓  Report •

#1
May 24, 2020 at 05:48:30
Do you have filenames with commas?

=====================

M2


Reply ↓  Report •

#2
May 24, 2020 at 05:58:54
Hi.
Yes it is titled string1,string2.bat

Reply ↓  Report •

#3
May 24, 2020 at 06:06:05
✔ Best Answer
@echo off & setLocal enableDELAYedeXpansioN

:main
for /f "tokens=1-2 delims=, " %%a in ('echo.%~N1') do (
echo 1st %%a
echo 2nd %%b
)
goto :eof

=====================

M2


Reply ↓  Report •

Related Solutions

#4
May 24, 2020 at 06:35:10
If it's the bat name replace %~N1 with %~N0

=====================

M2


Reply ↓  Report •

Ask Question