1.

Solve : Extract File Name from Folder?

Answer»

Please Help! I am trying to find a way to extract a file name from a DIRECTORY of files. For example, if you have a FOLDER named "C:\scanadm\file\in" that contains files
12343567.txt
7654321.txt

and you want to extract the name of each file in a for loop and store it in a variable:

FOR /R C:\scanadm\file\in %A IN (*.*) DO (Get Individual Name of File and Put in Variable)

How do you do this? I have been all over the internet, and cannot find this anywhere - It can't be that hard!!set un1=0
for /f "tokens=1* delims=" %%a in (' ') do (
call set /a un1=%%un1%%+1
call set D.%%un1%%=%%a
)

variables would be %D.1% %D.2% ectQuote

FOR /R C:\scanadm\file\in %A IN (*.*) DO (Get Individual Name of File and Put in Variable)

Not sure what the PROBLEM is. You have a variable (%A) which will contain the FULLY qualified file name.

If you don't want the path info, you can use:
Code: [Select]FOR /R C:\scanadm\file\in %A IN (*.*) DO (ECHO %~nxA)

Don't recommend using %~nxA; the /R switch walks the directory structure (recursion) and you may want to keep file names unique.






Discussion

No Comment Found