Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading directories & subdirectories

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
Just wondering if anyone can help. I'm still having problems with my directory traversal code.

I have a directory name e.g. C:/3rdContact/scripts

Within this directory i have subdirectories & files of all types. I want to zone in on files of type ".py".

e.g
C:/3rdContact/scripts/system/Campaign/viewAll.py
:
C:/3rdContact/scripts/excel.bat
:
C:/3rdContact/scripts/lisitng/Campaign/add.py
C:/3rdContact/scripts/lisitng/Campaign/view.py
:
:
C:/3rdContact/scripts/lisitng/Leisure/update.py


I basically want to read to the end of the directories and execute files of type .py.


Any help would be greatly appreciated,

Efa




 
You can use a FilenameFilter when list()ing - have a look at the API documentation - what you look for is at the following URL:


You can there also browse to other classes (such as the FilenameFilter) and look up how to implement or use them. I'd recommend to download the API documentation anyway.
For the filter you have to create an accept() function that looks if the name String endsWith(".py");

So in your list there will only be files that end with ".py". For the directory traversal you will of course have to get another list that checks for each name you get with the list if it's a directory (by concatenating path string and filename string you get something near the future path string - did not try it out though) and then do the same function again recursively. You needn't even do loop prevention - directories cannot contain themselves :)

Good luck
allow thyself to be the spark that lights the fire
haslo@haslo.ch - www.haslo.ch​
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top