1

I'm admittedly new to using batch commands so i'm not sure if this is at all possible, if it isn't please let me know. Recently I made a simple batch command to list the directories of all files ending in .exe and out putting it into a text file i'm calling testpaths.txt

dir C:\*.exe /s /b >> testpaths.txt

This command works as intended and lists the entire directory like this

C:\Windows\notepad.exe

What I am looking to do is to write a script searching this document and separating for lack of a better term the part of the string that says *.exe so it looks like

notepad.exe

I am totally lost as to where or how I could even accomplish this as I am brand new to this. Any help would be very much appreciated, thank you!

  • It's unclear what you ask. You want to remove the rest so that only filename.exe remain (as in remove the rest of the path) ? – Overmind Jun 14 '17 at 9:10
  • Which software you are using for the search of the document and to extract the result – Sam Jun 14 '17 at 9:14
0

How do I extract the filename from a list of files?

Use the following batch file:

@echo off
setlocal enabledelayedexpansion
dir C:\*.exe /s /b >> testpaths.txt
rem read the file one line at a time
for /f "usebackq" %%i in (`type testpaths.txt`) do (
  rem extract the filename
  echo %%~nxi
  )
endlocal

Further Reading

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.