Note: Use command line flags to prefix scripts with multiple parameters. (For example:
-d or -p or ...) Search for a module that will do this function.
Project #1
List all of the files in a directory tree:
- List all of the files in a directory tree.
- Skip all special files (dot files).
- Accept a starting directory on the command line.
If none is entered, asking the user to enter a starting directory.
If none is given, use the current directory.
- List the names of the files in each directory in sort order.
- Display the directory (or sub-directory) path
before listing the files found there.
- Use a recursive function.
- If "--help" or "-h" is entered on the comand line,
display help text and exit the script.
(Should "--help" or "-h" be case insensitive.)
Project #2
List all of the files in a directory tree that match a regular expression pattern:
- Modify project #1
- Accept a regular expression pattern on the command line.
If none is entered, asking the user to enter a pattern.
If none is given, exit the script.
- List all of the files in a directory tree that match the pattern.
Project #3
List all of the files in a directory tree owned by a specified user:
- Modify project #1
- Accept a user name on the command line.
If none is entered, ask the user to enter a user name.
If none is given, exit the script.
- List all of the files owned by a user.
Project #4
List all of the files in a directory tree >= to a specified size:
- Modify project #1
- Accept a size on the command line.
If none is entered, ask the user to enter a size.
In none is given, exit the script.
- List all of the files >= to a size.
- see the following code example:
import os, sys
statinfo = os.stat('abc.py')
print (statinfo)
Project #5
Rename all of the files in a directory or directory tree:
- Match file names using regular expressions.
- Rename matched files.
- List the files old and new name.
Project #6
Search a directory or directory tree for files:
- Ask the user for a partial file name.
- Match file names.
- List the files.
Project #7
Given two directories:
- list the files in one directory and not the other.
- List the files in in both directories.
Given N directories:
- list the files in only one directory.
- List the files in that are in only two directories.
- To keep the testing simple, use three or four directories.
However, the program should work for N directories.
Project #8
Count the words in a text file and display statistics.
What is a word?
- words are one or more characters seperated by spaces (whitespace)
- the last word in a sentence may have punctuation as its last character
- a word may also have punctuation as its first character (i.e."abc")
- some words are capitalized but are the same word (i.e. The and the)
The program should do the following:
- read a text file (ASCII vs UTF-8?)
- count the total number of words in the file
- Count how many times each word was found in the file
- display the total of words in the file
- display the number of times each word was found in
the file. (sort the words before displaying the counts.)
Download and use the text files for testing:
Note: Search for Python functions and methods that can split a line of text into
individual words.
Project #9
Search text files in a directory for a string pattern.
This will be a limited version of the Linux GREP utility.
The program should do the following:
- ask the user for a regular expression to match
- the names of files to be searched
- the text in the files to search for
- provide default values for the regular expressions
- search all of the files that match the regular expression
- for each line that matches print
- the file name
- the line number
- the complete line
- do case insensitive searches
- search the current directory
An example of possible output
---------- My Grep Utility -----------------------
Enter regexp search pattern [error] : xyz
Enter regexp file name pattern [\.py$] :
==================================================
Start time = Dec 8 2007 23:41:45
File pattern = \.py$
Directory = ./
String pattern = xyz
==================================================
xyz.py[7] import xyzconfig as ABC
xyzconfig.py[2] # configuration parameters for xyz
==================================================
Dirs processed = 1
Files processed = 61
Lines matched = 2
Lines processed = 3090
==================================================
After it is working try adding ...
- add case sensitive and insensitive searches
- search a directory and sub-directories
- add multiple regular expressions for the searches