Get file names containing "Apple" without full path

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
kaba
Posts: 2
Joined: 30 Jul 2013 11:05

Get file names containing "Apple" without full path

#1 Post by kaba » 30 Jul 2013 15:43

I am trying to create a list of all file names with the word "Apple" but I do not want the full file path, just the file name. File extension is not needed either but I can deal with it (they are all pdf). Currently I use this file but it gives the full file path which is a bit messy.

Code: Select all

dir /s /b /o "C:\Users\user\Documents\Fruit\*Apple*.pdf" > Apple.txt

I am open to modifying this or a completely different solution. I am a novice at batch scripting.

Dragokas
Posts: 43
Joined: 30 Jul 2013 09:42
Location: Ukraine, USSR
Contact:

Re: Get file names containing "Apple" without full path

#2 Post by Dragokas » 30 Jul 2013 16:17

Hello, kaba.

It will write all file names by %mask% (*apple*.pdf) in folder %src% recursively with subfolders -> to the file Apple.txt near this batch. (just file names without extensions).

Code: Select all

@echo off
SetLocal EnableExtensions

set src=%HomeDrive%%HomePath%\Documents\Fruit
set mask=*apple*.pdf

(
  for /F "delims=" %%F in ('dir /B /S /A-D "%src%\%mask%"') do echo %%~nF
) > "%~dp0Apple.txt"


Best regards, Alex.

kaba
Posts: 2
Joined: 30 Jul 2013 11:05

Re: Get file names containing "Apple" without full path

#3 Post by kaba » 31 Jul 2013 10:19

Thanks Alex. This is exactly what I wanted to do.

Post Reply