文件名或数字错误:vbs错误

比拉尔

编程新手。我试图制作一个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
丰富

行。所以它应该看起来像这样:

   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

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

文件名或数字错误:vbs错误

来自分类Dev

Unix套接字文件名错误

来自分类Dev

TFS搜索错误的文件名

来自分类Dev

wget Unicode文件名错误

来自分类Dev

更改文件名后出现错误

来自分类Dev

scp:错误:意外的文件名:

来自分类Dev

命令“ stat”的文件名过长错误

来自分类Dev

包含括号的文件名错误

来自分类Dev

在文件名上出现错误

来自分类Dev

恢复编码错误的文件名

来自分类Dev

Unix套接字文件名错误

来自分类Dev

xargs错误:文件名太长

来自分类Dev

strncpy 函数产生错误的文件名

来自分类Dev

创建 Ifstream 对象的文件名错误

来自分类Dev

错误:给出了多个文件名

来自分类Dev

链接错误:<文件名> .asm:错误的目标文件

来自分类Dev

VisualD的“ OPTLINK:错误118:预期的文件名”错误

来自分类Dev

无法打开“文件名”:找不到文件(文件:<错误的文件路径>/文件名)

来自分类Dev

CreateProcess错误= 206,文件名或扩展名太长

来自分类Dev

Createprocess错误= 206; 文件名或扩展名太长

来自分类Dev

FFMPEG出现错误-文件名或扩展名太长

来自分类Dev

FTP文件上传-文件名编码错误

来自分类Dev

由于文件名中的“ /”,Python文件写入错误

来自分类Dev

Python3.3 type =文件名错误

来自分类Dev

ejs错误“包含”要求使用“文件名”选项

来自分类Dev

Os X Yosemite Qt拖放文件名错误

来自分类Dev

php错误:“文件名不能为空”

来自分类Dev

ionic build产生错误的apk文件名

来自分类Dev

Maven程序集插件,错误的依赖文件名