Computing.Net > Forums > Programming > Batch Script Search Function

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch Script Search Function

Reply to Message Icon

Name: thePowerOf2Bears
Date: October 13, 2006 at 16:30:39 Pacific
OS: XP Pro
CPU/Ram: 4200+ / 4gb
Product: AMD/Athlon
Comment:

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




Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: October 14, 2006 at 09:09:23 Pacific
Reply:

This will get the names. If you want to keep the path ut will need more work.

::== numsonly.bat
@echo off > %TEMP%\~log
setLocal EnableDelayedExpansion

for /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
:: DONE

BTW, how many bears you got? 2?


=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 2
Name: Mechanix2Go
Date: October 14, 2006 at 09:34:05 Pacific
Reply:

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



0

Response Number 3
Name: Mechanix2Go
Date: October 14, 2006 at 10:08:42 Pacific
Reply:

This should do it:

::== 2bears.bat
@echo off > onlynums.log
setLocal EnableDelayedExpansion

for /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



0

Response Number 4
Name: thePowerOf2Bears
Date: October 14, 2006 at 16:38:40 Pacific
Reply:

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

Cheers,
Matt


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch Script Search Function

PHP search function www.computing.net/answers/programming/php-search-function/13314.html

Batch script Help www.computing.net/answers/programming/batch-script-help/12286.html

Batch Scripting .REG autostart Help www.computing.net/answers/programming/batch-scripting-reg-autostart-help/9463.html