我可以复制,但我不知道要放什么来获取当前目录,所以文件在哪里并不重要,但它会复制它。代码将是这样的:
Set fso = CreateObject("Scripting.FileSystemObject")
strFolder = fso.GetParentFolderName(WScript.ScriptFullName)
Const DestinationFile = "C:\Users\John\Foldar\output.vbs"
Const SourceFile = "fso.BuildPath (strFolder, "getty.vbs")"
If fso.FileExists(DestinationFile) Then
If Not fso.GetFile(DestinationFile).Attributes And 1 Then
fso.CopyFile SourceFile, "C:\Users\John\AnyFile\", True
Else
fso.GetFile(DestinationFile).Attributes = fso.GetFile(DestinationFile).Attributes - 1
fso.CopyFile SourceFile, "C:\Users\John\AnyFile\", True
fso.GetFile(DestinationFile).Attributes = fso.GetFile(DestinationFile).Attributes + 1
End If
Else
fso.CopyFile SourceFile, "C:\Users\John\AnyFile\", True
End If
Set fso = Nothing
我需要的是这样的:
Const SourceFile = "currentplace\something.vbs"
或类似的东西。因为我在第 4 char 48 行收到错误 Expected end of statement 。
这是我更新的代码:
Set fso = CreateObject("Scripting.FileSystemObject")
strFolder = fso.GetFolder(".").Path
DestinationFile = "C:\Test\getty.vbs"
SourceFile = fso.BuildPath(dir, getty.vbs)
If fso.FileExists(DestinationFile) Then
If Not fso.GetFile(DestinationFile).Attributes And 1 Then
fso.CopyFile SourceFile, "C:\Test\", True
Else
fso.GetFile(DestinationFile).Attributes = fso.GetFile(DestinationFile).Attributes - 1
fso.CopyFile SourceFile, "C:\Test\", True
fso.GetFile(DestinationFile).Attributes = fso.GetFile(DestinationFile).Attributes + 1
End If
Else
fso.CopyFile SourceFile, "C:\Test\", True
End If
Set fso = Nothing