2013-02-15 66 views
1

一位朋友和我開始構建一個VBScript,目標是在插入外部硬盤或USB時複製所有打開的文件/某些特定格式的文檔(如pdf,pptx)電腦。我們得到了我們的腳本,只是將特定格式的所有文檔從外部硬盤/ USB複製到我的電腦,但是我們必須在插入外部硬盤/ USB後手動執行腳本。vbscript從外部磁盤複製文件

我們想劇本做:自動

  1. 開始,當外部硬盤/ USB插入
  2. 副本後不顯示彈出
  3. Possibily只複製文件由用戶

在這裏隆重開幕(PDF,JPEG,PPTX)是我們到目前爲止已經完成:

' foreach.vbs 
' Testing the for each function on files 
' 

' BEGIN 

' Create a File System Object to handle files and folders 
Set fso = CreateObject("Scripting.FileSystemObject") 

' Some vars 
src = "C:\" ' The source of search, should be changed before use 
dest = "c:\temp\1\" ' destination where we will copy files to 

' It would be a bright idead to force and/or create dest before 
' starting copy 
fso.CreateFolder(dest) 

Set ofolder = fso.GetFolder(src) ' set as object 
' get all files inside the specified folder 
Set allfiles = ofolder.Files 
' Enter a For Each Loop that will process each of the files 
For Each sfile in allfiles 
' Better get all extensions in lower case 
If LCASE(fso.GetExtensionName(sfile.Name)) = "bat" then 
' Print out what we find 
wscript.echo sfile.Name 
fso.CopyFile sfile, dest 
End If 
Next 
+0

「你打開的文件」究竟是什麼意思?您的腳本只是將文件從一個地方複製到另一個地方,而且似乎與插入外部磁盤沒有任何關係 - 外部磁盤的目標可能會根據驅動器號碼的變化而變化... – Krease 2013-02-15 22:39:28

+0

由'任何選定的文件'我的意思是任何文件打開像一張圖片或PDF .....是啊,它沒有插入外部磁盤,但這是因爲我不知道該怎麼做,這就是爲什麼我問你們@Chris – user2010187 2013-02-16 01:14:40

+0

??? @Chris更清楚嗎? – user2010187 2013-02-17 10:14:03

回答

0

如果我得到它的權利,您的實際問題是如何檢測USB驅動器已插入

不幸的是,您需要一些事件驅動語言才能做到這一點,而不是VBScript。 但是,如果你不想去編程,爲什麼不使用Task Scheduler

P.S.其實,this topic(我不喜歡無限循環,但是)是一個可能的答案。