pythonÌìÌì½ø²½(2) Îļþ²Ù×÷Ö®±éÀúĿ¼
PythonµÄosÄ£¿é£¬°üº¬ÁËÆÕ±éµÄ²Ù×÷ϵͳ¹¦ÄÜ£¬ÕâÀïÖ÷ҪѧϰÓë·¾¶Ïà¹ØµÄº¯Êý£º
os.listdir(dirname)£ºÁгödirnameϵÄĿ¼ºÍÎļþ
os.getcwd()£º»ñµÃµ±Ç°¹¤×÷Ŀ¼
os.curdir:·µ»Øµ±Ç°Ä¿Â¼£¨'.')
os.chdir(dirname):¸Ä±ä¹¤×÷Ŀ¼µ½dirname
os.path.isdir(name):ÅжÏnameÊDz»ÊÇÒ»¸öĿ¼£¬name²»ÊÇĿ¼¾Í·µ»Øfalse
os.path.isfile(name):ÅжÏnameÊDz»ÊÇÒ»¸öÎļþ£¬²»´æÔÚnameÒ²·µ»Øfalse
os.path.exists(name):ÅжÏÊÇ·ñ´æÔÚÎļþ»òĿ¼name
os.path.getsize(name):»ñµÃÎļþ´óС£¬Èç¹ûnameÊÇĿ¼·µ»Ø0
os.path.abspath(name):»ñµÃ¾ø¶Ô·¾¶
os.path.normpath(path):¹æ·¶path×Ö·û´®ÐÎʽ
os.path.split(name):·Ö¸îÎļþÃûÓëĿ¼£¨ÊÂʵÉÏ£¬Èç¹ûÄãÍêȫʹÓÃĿ¼£¬ËüÒ²»á½«×îºóÒ»¸öĿ¼×÷ΪÎļþÃû¶ø·ÖÀ룬ͬʱËü²»»áÅжÏÎļþ»òĿ¼ÊÇ·ñ´æÔÚ£©
os.path.splitext():·ÖÀëÎļþÃûÓëÀ©Õ¹Ãû
os.path.join(path,name):Á¬½ÓĿ¼ÓëÎļþÃû»òĿ¼
os.path.basename(path):·µ»ØÎļþÃû
os.path.dirname(path):·µ»ØÎļþ·¾¶
1¡¢os.path·½·¨
ͨ¹ý´«ÈëÐèÒª±éÀúµÄĿ¼£¬ÁгöĿ¼ÏµÄËùÓÐÎļþ²¢Í³¼ÆÎļþÊý£¬osÌṩµÄpathÄ£¿éÄܶÔĿ¼·Ç³£Áé»îµÄ²Ù×÷¡£
import os,sys
def listdir(dir,file):
file.write(dir + '\n')
fielnum = 0
list = os.listdir(dir) #ÁгöĿ¼ÏµÄËùÓÐÎļþºÍĿ¼
for line in list:
filepath = os.path.join(dir,line)
if os.path.isdir(filepath): #Èç¹ûfilepathÊÇĿ¼£¬ÔòÔÙÁгö¸ÃĿ¼ÏµÄËùÓÐÎļþ
myfile.write(' ' + line + '\\'+'\n')
for li in os.listdir(filepath):
myfile.write(' '+li + '\n')
fielnum = fielnum + 1
elif os.path: #Èç¹ûfilepathÊÇÎļþ
Ïà¹ØÎĵµ£º
ÓÃPythonµ¼³öQQ¿Õ¼äµÄÈÕÖ¾µ½WordPress
ÎÄÕÂÀ´Ô´£ºhttp://www.keakon.cn/bbs/thread-964-1-1.html·½·¨ºÜ¼òµ¥£¬ÕÒ³öÈÕÖ¾µÄµØÖ·£¬ÔÙ±éÀúÁгöÈÕÖ¾µÄÄÚÈÝ¡£
ÒòΪµ¥´¿µ¼³öûÓ㬻¹µÃת»»³ÉÆäËû¸ñʽ£¬ËùÒÔÎÒ±£´æµ½Ò»¸öÁбíÀÿƪÈÕÖ¾¶¼¶ÔÓ¦ÆäÖеÄÒ»¸ö×ÖµäÔªËØ£¬×ÖµäµÄÊôÐÔ¶¼ÓÃunicode±àÂë¡£
È»ºódump³öÀ´£¬¿ÉÒÔ·½±ãÒÔºóÓÃPyth ......
Ethereal ×Ô´øÐí¶àÐÒéµÄ decoder,¼òµ¥,Ò×ÓÃ,»ùÓÚwinpcapµÄÒ»¸ö¿ªÔ´µÄÈí¼þ.µ«ÊÇËüµÄ¼Ü¹¹²¢²»Áé»î,ÈçºÎÄãÒª¼ÓÈëÒ»¸ö×Ô¼º¶¨ÒåµÄµÄ½âÂëÆ÷,µÃÈ¥ÐÞ¸Ä EtherealµÄ´úÂë,ÔÙÖØÐ±àÒë,ºÜ·³Ëö.¶ÔÓÚÒ»°ãµÄÃ÷ÎÄ ÐÒé,ûÓÐʲôÎÊÌâ,µ«ÊǶÔÓÚ¼ÓÃÜÐÒé,±ÈÈçÍøÂçÓÎÏ·,¿Í»§¶Ë³ÌÐòÒ»°ã»áÔÚ¸ÕÁ¬½ÓÉϵÄʱºò,·¢ËÍÒ»¸öËæ»úÃÜÔ¿,¶øºóµÄ±¨Îͼ»áÓÃÕ⸠......
½ñÌì¿´¿´ÈçºÎÓÃpythonʵÏÖ×¥°ü¡£
ÒÔǰÎÒÃÇÔøÓùýwinpcapʵÏÖ×¥°ü£¬Æäʵ½ñÌìÎÒÃÇ»¹ÊÇÓÃËü£¬Ö»²»¹ýÊÇËüÔÚpythonϵÄÄ£¿é£¬ÔÚÓÃ֮ǰÎÒÃDZØÐëÏÈÏÂÔØÁ½¸ö¿â£¬pcap¿âºÍdpkt¿â£¬Õâ¸ö¿ÉÒÔÔÚGoogle codeÀïºÜÈÝÒ×ÕÒµ½£¬ÐèҪעÒâµÄÊÇpcapÖ»Ö§³Öµ½python2.5 £¬ËùÒÔÎÒÃÇÒªÓÃ2.5À´±àд¡£
°²×°ÍêÁ ......
1. µÚÒ»Õ¡¡Python¿ìËÙÈëÃÅ
±¾ÕÂÊÇPythonµÄ¿ìËÙÈëÃÅ£¬ÔÚÕâÒ»Õ²¢²»Éæ¼°pythonµÄÌØÊâ¹æÔòºÍϸ½Ú£¬Ä¿±êÊÇͨ¹ýʾÀýʹÄã¿ìËÙÁ˽âPythonÓïÑÔµÄÌØµã¡£±¾Õ¼òÒª½éÉÜÁ˱äÁ¿,±í´ïʽ,¿ØÖÆÁ÷,º¯ÊýÒÔ¼°ÊäÈë/Êä³öµÄ»ù±¾¸ÅÄî,ÔÚÕâÒ»Õ²»Éæ¼°PythonÓïÑԵĸ߼¶ÌØÐÔ¡£¾¡¹ÜÈç´Ë£¬ÓоÑéµÄ³ÌÐòÔ±»¹ÊÇÄܹ»Í¨¹ýÔĶÁ±¾ÕµIJÄÁÏ´´½¨¸ß¼¶³ÌÐò¡£ÎÒÃÇ ......
ÕæÊǵ¹Ã¹£¬¸ÕÂò²»¾ÃµÄÒÆ¶¯Ó²ÅÌ£¬×òÌìɾ³ýÒ»¸ö·ÖÇøÊ§°Üºó£¬¼¸¸ö·ÖÇø¶¼²»¼ûÁË£¬ÄÃÈ¥ÐÞ£¬Î´¹û
»»Á˸öÐµģ¬µ«ÆäÖÐÊý¾ÝȫûÁË¡£ÄÇÊÇÎÒÆ½Ê±ÊÕ¼¯µÄºÜÓÐÓõÄ×ÊÁÏ
ºÜ¶à¶¼¿ÉÒÔÖØÐÂÏÂÔØ£¬µ«ÔõÄÜÏëÆðÓ²ÅÌÖеÄËùÓж«Î÷
½ñÌì»»Ó²ÅÌ»ØÀ´
¾ÍÏñдһ¸ö±£´æÖ¸¶¨Â·¾¶ÏÂËùÓÐÎļþ¼ÐºÍÎļþÃûµÄ³ÌÐò
ÕâÑù£¬Èç¹û¶«Î÷¶ªÁË£¬¿´¿´ÄÇÀïÓÐЩʲô£¬Ò² ......