wjason 发表于 2013-1-28 19:17:34

python练习贴08 读写剪切板

同事经常会给我发一些这样的路径,
\\Server\DepA\ProjB\other\...\...\aDir\
\\Server\DepA\ProjB\other\...\...\aDir\aFile
 
然后我需要代开他们,看一看,或者追加一些内容。
这一过程很繁琐,于是今天的需求便是写一个python脚本。
直接打开剪切板中的资源,如果他是一个合法路径的话。
 
其中下面这两个方法是读取和设置剪切板
getClipboardText
setClipboardText
使用的是pywin32
 
 
__author__="wjason"__date__ ="$2009-10-28 14:56:42$"import os.pathimport win32clipboardimport win32condef openResource(path):    if not os.path.exists(path):      return    if os.path.isdir(path):      cmd = 'cmd /C call explorer "'+path+'"'    else:      cmd = 'cmd /C call "'+path+'"'      #os.popen(cmd)    #os.system(cmd)    import subprocess    subprocess.Popen(cmd, shell=True)def getClipboardText():    win32clipboard.OpenClipboard()    result = win32clipboard.GetClipboardData(win32con.CF_TEXT)    win32clipboard.CloseClipboard()    return resultdef setClipboardText(aString):    win32clipboard.OpenClipboard()    win32clipboard.EmptyClipboard()    win32clipboard.SetClipboardData(win32con.CF_TEXT, aString)    win32clipboard.CloseClipboard()if __name__ == "__main__":    print getClipboardText()    openResource(getClipboardText())  
 
 
 
 
 
 
页: [1]
查看完整版本: python练习贴08 读写剪切板