Here is my another challenge. When I pass the file name into for loop, I want to get a specific word from the file name and need to pass that as a parameter as well.

For eg: When there are 5 files in a folder say

Encrypted_abc_1.xml Encrypted_xyz_2.xml Encrypted_hij_3.xml Encrypted_klm_4.xml Encrypted_nop_5.xml

I want to pass the file name Encrypted_abc_1.xml and abc into the for loop. I got the answer for both in seperate for loops however how can i merge into one single for loop

First for loop will fetch the word

for /f "tokens=2 delims=_." %%a in (Encrypted_*.xml /b) do (

Echo %%a

Another for loop will get the full file name

for /R "%Path%" %%f in (Encrypted_*.xml) do (

Echo %%f

Below is the revised code as of now but still it doesnt work as Path is not recognised

@ECHO OFF
SET Path=%1

SET Path=%Path:"=%
Echo "%Path%"
::SETLOCAL

for /f "tokens=*" %%a in ('%Path% /b Encrypted*.xml') do (
     for /f "tokens=2 delims=_" %%f in ("%%a") do (
    Echo %%f
    ECHO %%a
)
)

Pause:
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.