Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 16th, 2005, 2:52 PM   #1
SaturN
Programmer
 
Join Date: Apr 2005
Location: Uk
Posts: 68
Rep Power: 4 SaturN is on a distinguished road
Post Protected Folders

Ok, has no use to me, probably has NO use to anyone, But i made it just to see if it works basically..
All it will do is make sure that NO files can be added to a protected folder specifyed by 'path' variable. And will delete anything that is not added to a 'whitelist'.. Have fun with it, don't really care if there is no use! lol..
import os
from time import sleep
whitelist = [
	'protected.txt',   #add files to this to 'protect' from deletion
	'save.doc'
	]
path = YOUR GIVEN PATH
while(1):
	for root, dirs, files in os.walk(path):
		for name in files:
			if name not in whitelist:
				try:
					os.remove(os.path.join(path, name))
				except:
					pass
	sleep(4)

Designed to run as a 'background' process, so save it as a '.pyw'
ps: There is no break from the loop, to close search processes in the windows task manager for 'pythonw.exe' and close that to close the program..

__________________
while me is alive:
	make(life,simple)
SaturN is offline   Reply With Quote
Old Jul 16th, 2005, 3:28 PM   #2
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Quote:
Designed to run as a 'background' process, so save it as a '.pyw'
Lazy, Windows only solution
You're meant to fork your process into the background. How to do that has been addressed in another thread.

If you want a solution that doesn't eat CPU, yet still gets informed of file additions/modifications in a directory almost instantaneously, look into the appropriate technology for your OS that informs your daemon of file i/o events that occur in a certain directory (e.g FAM on *nix, KDirWatch when using kdelibs, etc).
Cerulean is offline   Reply With Quote
Old Jul 16th, 2005, 4:58 PM   #3
SaturN
Programmer
 
Join Date: Apr 2005
Location: Uk
Posts: 68
Rep Power: 4 SaturN is on a distinguished road
I'm a lazy person!!
Great excuse to pull *still learning like's the feed-back*
hehe, i'll look in to 'forking' processes now! As for the second part All i'm gonna say is, please don't confuse me!!
__________________
while me is alive:
	make(life,simple)
SaturN is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:18 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC