Author Topic: Search script  (Read 212 times)

Winning

  • Hero Member
  • *****
  • Posts: 1632
  • Reputation: 26
  • I think I saw this in a movie
  • Computers: Toshiba Thrive Tablet
  • iDevices: iPod touch 4G
Search script
« on: August 30, 2012, 03:57:50 pm »
I found this script online and I made a few tweaks to it but it appears that it only searches the current directory. Is there a way to make it search the entire file system. Here is the script:

import stat
import sys
import os
import string
import commands

try:
    pattern = raw_input("Enter the file name to search for:\n")
    commandString = "find " + pattern
    commandOutput = commands.getoutput(commandString)
    findResults = string.split(commandOutput, "\n")

    print "Files:"
    print commandOutput
    print "========================================="
    for file in findResults:
        mode=stat.S_IMODE(os.lstat(file)[stat.ST_MODE])
except:
    print "There was a problem in searching"
« Last Edit: August 30, 2012, 04:14:12 pm by Winning »

A3MIRAL

  • Leader
  • Hero Member
  • *****
  • Posts: 2899
  • Reputation: 105
  • A3MIRAL -- Reporting for Duty
    • A3MIRAL
  • Badges:
  • Computers: Dell XPS15 (6 GB ram, Core i7 @ 2.0 GHz, 750 GB HDD @ 7200 RPM)
  • iDevices: iPod touch 3G 32GB, iPhone 5 32GB
Re: Search script
« Reply #1 on: August 30, 2012, 04:02:42 pm »
Try
Code: [Select]
commandString = "find /  " + pattern

Winning

  • Hero Member
  • *****
  • Posts: 1632
  • Reputation: 26
  • I think I saw this in a movie
  • Computers: Toshiba Thrive Tablet
  • iDevices: iPod touch 4G
Re: Search script
« Reply #2 on: August 30, 2012, 04:17:44 pm »
Nope tried and it didnt work.

Would it have to do with its not trying to find the files in / but finding a file /?

A3MIRAL

  • Leader
  • Hero Member
  • *****
  • Posts: 2899
  • Reputation: 105
  • A3MIRAL -- Reporting for Duty
    • A3MIRAL
  • Badges:
  • Computers: Dell XPS15 (6 GB ram, Core i7 @ 2.0 GHz, 750 GB HDD @ 7200 RPM)
  • iDevices: iPod touch 3G 32GB, iPhone 5 32GB
Re: Search script
« Reply #3 on: August 30, 2012, 04:18:37 pm »
In terminal
Code: [Select]
find -help

Trcx528

  • Haxor
  • Hero Member
  • *****
  • Posts: 4502
  • Reputation: 166
  • Google it!
    • iNinjas
  • Badges:
  • Computers: 13" 2011 Macbook Pro, 120 GB SSD and 16 GB of Ram
  • iDevices: None
Re: Search script
« Reply #4 on: August 30, 2012, 11:58:56 pm »
Try
Code: [Select]
commandString = "find /  " + pattern

Close, do
Code: [Select]
commandString = "find /  -name " + pattern

Don't like seeing ads? Click here to register!