友人と私は、コンピューターに外付けハードディスクまたは USB を挿入したときに、開いているファイルや特定の形式のドキュメント (pdf、pptx など) をコピーすることを目的として、VBScript の作成を開始しました。特定の形式のすべてのドキュメントを外付けハードディスク/USB からコンピューターにコピーするだけのスクリプトを取得しましたが、外付けハードディスク/USB を挿入した後、スクリプトを手動で実行する必要があります。
スクリプトに実行させたいこと:
- 外付けハードディスク/USB挿入時に自動起動
- コピー後にポップアップを表示しない
- ユーザーが開いているファイル (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