【问题标题】:vbscript to copy file from an external diskvbscript 从外部磁盘复制文件
【发布时间】:2013-02-15 22:17:55
【问题描述】:

我和一个朋友开始构建一个 VBScript,目标是当我们在计算机上插入外部硬盘或 USB 时复制任何打开的文件/某些特定格式的文档(如 pdf、pptx)。我们的脚本仅将特定格式的所有文档从外部硬盘/USB 复制到我的计算机,但我们必须在插入外部硬盘/USB 后手动执行脚本。

我们希望脚本做什么:

  1. 插入外部硬盘/USB 时自动启动
  2. 复制后不显示弹出窗口
  3. 可能只复制用户打开的文件(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

【问题讨论】:

  • “任何打开的文件”到底是什么意思?您的脚本只是将文件从一个地方复制到另一个地方,并且似乎与插入外部磁盘没有任何关系 - 外部磁盘的目标可能会根据可用的驱动器号而改变......
  • “任何打开的文件”我的意思是任何文件都像图片或pdf一样打开.....是的,它没有插入外部磁盘,但这是因为我不知道该怎么做这就是为什么我要问你们@Chris
  • ??? @Chris 更清楚了吗?
  • 对不起;我想我在这里帮不了多少忙。

标签: windows vbscript


【解决方案1】:

如果我猜对了,您的实际问题是如何检测 USB 驱动器已插入

您需要一些事件驱动语言来执行此操作,不幸的是,不是 VBScript。 但是如果你不想编程,为什么不使用Task Scheduler

附:实际上,this topic(我不喜欢无限循环,但是)是一个可能的答案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-25
    • 1970-01-01
    • 2014-01-29
    • 2011-01-14
    • 1970-01-01
    • 2019-03-13
    • 2011-02-14
    • 1970-01-01
    相关资源
    最近更新 更多