Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hey guys. I was just wondering if it was possible to write a batch script that searches through a directory (and all sub-directories) and returns all files that a)don't have an extension, and b)start with a number.
I know that I can use the following to search for files with no extension, and then add those files to an output text file:
dir *. /s /a-d > "c:\new folder\output.txt"
However, I do not know how to ONLY return those files that begin with a numerical value.
Anyone have any ideas? Help would be much appreciated!
Cheers,
Matt

This will get the names. If you want to keep the path ut will need more work.
::== numsonly.bat
@echo off > %TEMP%\~log
setLocal EnableDelayedExpansionfor /f "tokens=* delims=" %%F in ('dir /s/b/a-d \temp\-\*.') do (
set FNAME=%%~nF
set first=!FNAME:~0,1!
if 10 gtr !first! echo !FNAME! >> %TEMP%\~log
)
find /v "!" < %TEMP%\~log | find /v "#" | find /v "$" > onlynums.log
:: DONEBTW, how many bears you got? 2?
=====================================
If at first you don't succeed, you're about average.M2

OOPS
As the Brits say, 'ang on.
The last lline will filter out ! # and $ if they occur antwhere in the file name.
Lemme work on it.
=====================================
If at first you don't succeed, you're about average.M2

This should do it:
::== 2bears.bat
@echo off > onlynums.log
setLocal EnableDelayedExpansionfor /L %%N in (0 1 9) do (
for /f "tokens=* delims=" %%F in ('dir /s/b/a-d \temp\-\%%N*.') do (
echo %%F >> onlynums.log
)
)
::== DONE
=====================================
If at first you don't succeed, you're about average.M2

Wow! Thanks alot mate, worked first time. And yep, sadly only the 2 bears...but I have plans to expand :D
Cheers,
Matt

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |