Hi,
this time trying to output a folder name then output partial of its name into variable
Let's say I got the following path showing the folder
C:\auto_pkg_build\Sources\Source_schemes\QA_Infra\T501-08700-0100-T3_QA_Infra-SL_0102_signed_SL_Key_schemes_pack\T501-08700-0100\...\...
Under Source_schemes folder, there are many different subfolders similar as T501-08700-0100-T3_QA_Infra-SL_0102_signed_SL_Key_schemes_pack
I have a known value or variable as T501-08700-0100 as the above case.
What I need is to extract T501-08700-0100-T3_QA_Infra-SL_0102_signed_SL_Key_schemes_pack
then output T3_QA_Infra-SL_0102_signed_SL_Key_schemes_pack as variable
Thanks
Try to read folder name then output partial name of the folder as variable
Moderator: DosItHelp
Re: Try to read folder name then output partial name of the folder as variable
Code: Select all
pushd C:\auto_pkg_build\Sources\Source_schemes\QA_Infra
for /D %%G in (*) DO (
FOR /F "TOKENS=3* delims=-" %%H in ("%%~G") DO echo %%I
)
popd
Re: Try to read folder name then output partial name of the folder as variable
Thanks Squashman!Squashman wrote: ↑18 Apr 2018 11:19Code: Select all
pushd C:\auto_pkg_build\Sources\Source_schemes\QA_Infra for /D %%G in (*) DO ( FOR /F "TOKENS=3* delims=-" %%H in ("%%~G") DO echo %%I ) popd
I tried your code with a little change and got the expected results
Code: Select all
@ECHO OFF
pushd C:\auto_pkg_build\Sources\Source_schemes\QA_Infra
if exist pkg_description.txt (del pkg_description.txt)
for /D %%G in (T501-08700-0100-*) DO (
FOR /F "TOKENS=4* delims=-" %%H in ("%%~G") DO echo %%H
)>>pkg_description.txt
popd
QA_Infra-SL_0102_signed_SL_Key_schemes_pack
otherwise I only got QA_Infra
But If I changed this string without - like this QA_Infra_SL_0102_signed_SL_Key_schemes_pack
Then after running the above code, I will get QA_Infra_SL_0102_signed_SL_Key_schemes_pack
Thanks
Re: Try to read folder name then output partial name of the folder as variable
What was wrong with using the FOR /F command as I provided it to you. Pretty sure it works the way you described your output in your first post in this thread.
Let's just test that from the cmd prompt real quick.
Let's just test that from the cmd prompt real quick.
Code: Select all
I:\>FOR /F "TOKENS=3* delims=-" %H in ("T501-08700-0100-T3_QA_Infra-SL_0102_signed_SL_Key_schemes_pack ") DO @echo %I
T3_QA_Infra-SL_0102_signed_SL_Key_schemes_pack
I:\>
Re: Try to read folder name then output partial name of the folder as variable
As I said in the first post, I only know T501-08700-0100 instead of T501-08700-0100-T3_QA_Infra-SL_0102_signed_SL_Key_schemes_packSquashman wrote: ↑18 Apr 2018 14:08What was wrong with using the FOR /F command as I provided it to you. Pretty sure it works the way you described your output in your first post in this thread.
Let's just test that from the cmd prompt real quick.Code: Select all
I:\>FOR /F "TOKENS=3* delims=-" %H in ("T501-08700-0100-T3_QA_Infra-SL_0102_signed_SL_Key_schemes_pack ") DO @echo %I T3_QA_Infra-SL_0102_signed_SL_Key_schemes_pack I:\>
from T501-08700-0100 to get T501-08700-0100-T3_QA_Infra-SL_0102_signed_SL_Key_schemes_pack then chop off to get
T3_QA_Infra-SL_0102_signed_SL_Key_schemes_pack as final results
Thanks
Re: Try to read folder name then output partial name of the folder as variable
I don't know how to better explain that the changes you made to the FOR /F command that I gave you will not work. If you use the FOR /F command as I posted in my code it will work.
I am tapping out of this thread.
I am tapping out of this thread.