Author Topic: python File Searcher  (Read 693 times)

0 Members and 1 Guest are viewing this topic.

Offline Clone

  • Peasant
  • *
  • Posts: 50
  • Cookies: 2
  • Always trying to find the value of x
    • View Profile
python File Searcher
« on: February 02, 2014, 09:11:19 pm »
This is a python script to search for files and directories in root.Its kinda slow i was hoping for corrections
Code: (Python) [Select]
import os
count=0
print"File Searcher"
print"---------------------------------------------------------------"
print"---------------------------------------------------------------"
filename=raw_input("Enter file name to be searched:")
print"Searching for %s..."% filename
for rootDir,dirs,files in os.walk("/"):
    for Dir in dirs:
        if Dir.endswith(filename):
            print count,".)PATH:",rootDir+"//"+Dir
            count=count+1
    for fileX in files:
        if fileX.endswith(filename):
            print count,".)PATH:",rootDir+"//"+fileX
            count=count+1
count=count-1           
print"End of search."
if count<=0:
    print"No results matching \"%s\" found"% filename
else:   
    print"No of results found matching \"%s\"is %d"% (filename,count)
« Last Edit: February 16, 2014, 06:15:48 pm by Clone »
One who walks the line between light and dark, with no ties to either side. No morals or emotions clouding their judgment,able to accomplish tasks and solve problems in the most efficient and logical way.

Offline Phage

  • VIP
  • Overlord
  • *
  • Posts: 1280
  • Cookies: 120
    • View Profile
Re: python File Searcher
« Reply #1 on: February 03, 2014, 08:19:29 am »
I don't really see the purpose for this tool, sorry. Pretty much all OS's has a feature like this built in.
"Ruby devs do, in fact, get all the girls. No girl wants a python, but EVERY girl wants rubies" - connection

"It always takes longer than you expect, even when you take into account Hofstadter’s Law."

Offline kenjoe41

  • Symphorophiliac Programmer
  • Administrator
  • Baron
  • *
  • Posts: 990
  • Cookies: 224
    • View Profile
Re: python File Searcher
« Reply #2 on: February 03, 2014, 09:22:08 am »
No problem if it is a learning project or can be use in another script for instance where you hate to call the system's Find.
If you can't explain it to a 6 year old, you don't understand it yourself.
http://upload.alpha.evilzone.org/index.php?page=img&img=GwkGGneGR7Pl222zVGmNTjerkhkYNGtBuiYXkpyNv4ScOAWQu0-Y8[<NgGw/hsq]>EvbQrOrousk[/img]