Vbscript 错误的文件名或编号:vbs错误

Vbscript 错误的文件名或编号:vbs错误,vbscript,Vbscript,sry的家伙们,我是编程新手。我试图制作一个vbscript,将vbs文件从当前位置处理到系统启动文件夹。但是我得到了错误的文件名或编号。但当我手动给出路径时,它就像一个符咒。我的代码自动选取的路径也是正确的。我不明白是什么问题。请帮帮我。这是我的密码 Set objShell = Wscript.CreateObject("Wscript.Shell") strMyPath = objShell.SpecialFolders("Startup") wscript.echo strPath ws

sry的家伙们,我是编程新手。我试图制作一个vbscript,将vbs文件从当前位置处理到系统启动文件夹。但是我得到了错误的文件名或编号。但当我手动给出路径时,它就像一个符咒。我的代码自动选取的路径也是正确的。我不明白是什么问题。请帮帮我。这是我的密码

Set objShell = Wscript.CreateObject("Wscript.Shell")
strMyPath = objShell.SpecialFolders("Startup")
wscript.echo strPath
wscript.echo strMyPath
'Const strMyPath = "C:\Users\Bilal\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\"
Const SourceFile = "abc.vbs"
Set fso = CreateObject("Scripting.FileSystemObject")
'Check to see if the file already exists in the destination folder
If fso.FileExists(strMyPath) Then
    'Check to see if the file is read-only
    If Not fso.GetFile(strMyPath).Attributes And 1 Then 
        'The file exists and is not read-only.  Safe to replace the file.
        fso.CopyFile SourceFile, strMyPath, True
    Else 
        'The file exists and is read-only.
        'Remove the read-only attribute
        fso.GetFile(strMyPath).Attributes = fso.GetFile(strMyPath).Attributes - 1
        'Replace the file
        fso.CopyFile SourceFile, strMyPath, True
        'Reapply the read-only attribute
        fso.GetFile(strMyPath).Attributes = fso.GetFile(strMyPath).Attributes + 1
    End If
Else
    'The file does not exist in the destination folder.  Safe to copy file to this folder.
    fso.CopyFile SourceFile, myStrPath, True
End If
Set fso = Nothing
使

If fso.FileExists(strMyPath) Then
“工作”,strMyPath必须包含有效的文件规范。据我所知,在代码中,它包含(destination?)文件夹的路径


使用正确命名的变量(名称),以明确它们是否包含文件夹或文件规范。

确定。所以它应该是这样的:

   Set objShell = Wscript.CreateObject("Wscript.Shell")
   strPath = objShell.SpecialFolders("Startup")
   strMyPath = strPath&"\"  
   Const SourceFile = "abc.vbs"
   strMyPath = strMyPath & SourceFile
   Set fso = CreateObject("Scripting.FileSystemObject")

    'Check to see if the file already exists in the destination folder
    If fso.FileExists(strMyPath) Then

    'Check to see if the file is read-only
    If Not fso.GetFile(strMyPath).Attributes And 1 Then 
        'The file exists and is not read-only.  Safe to replace the file.
        fso.CopyFile SourceFile, strMyPath, True
    Else 
        'The file exists and is read-only.
        'Remove the read-only attribute
        fso.GetFile(strMyPath).Attributes = fso.GetFile(strMyPath).Attributes - 1
        'Replace the file
        fso.CopyFile SourceFile, strMyPath, True
        'Reapply the read-only attribute
        fso.GetFile(strMyPath).Attributes = fso.GetFile(strMyPath).Attributes + 1
    End If
Else
    'The file does not exist in the destination folder.  Safe to copy file to this folder.
    fso.CopyFile SourceFile, strMyPath, True
End If
Set fso = Nothing

错误发生在哪一行?最后一个copy语句。文件不存在的情况。我已经注释了一个const variable语句。如果我用那句话,效果会很好。在那一行中,你使用的是
myStrPath
…它在任何地方都不会被设置。是的,我看到了并更正了。是的,目标文件夹。如果它是你试图验证存在的目标文件夹,为什么不使用“.FolderExists()”方法呢?正如我说的,我是新的。我没有太多的功能知识。我更正为:fso.CopyFile SourceFile,strMyPath,True