Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Extract File Name from Folder  (Read 2302 times)

0 Members and 1 Guest are viewing this topic.

codelady

  • Guest
Extract File Name from Folder
« on: December 19, 2007, 07:55:31 AM »
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!!

diablo416

  • Guest
Re: Extract File Name from Folder
« Reply #1 on: December 19, 2007, 08:22:47 AM »
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% ect

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Extract File Name from Folder
« Reply #2 on: December 19, 2007, 09:17:05 AM »
Quote
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.

 8)


The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein