为什么我得到“目录包含名称仅按大小写不同的条目”

问题描述 投票:0回答:1

我正在尝试用一些更新的功能修改代码,但是现在当我运行它时,无论我选择哪个最终选项,它都不会做任何事情,除了在尝试重命名文件或复制文件时给我一个错误。当它说需要对象然后错误文本是“目录包含名称仅按大小写不同的条目”时,这是什么意思?我以前从未见过它。 这是我的脚本:


set ws = createobject("wscript.shell")
Set fs = CreateObject("scripting.filesystemobject")
set sa = createobject("shell.application")

            Set ie=CreateObject("internetexplorer.application") 
            ie.AddressBar=False
            ie.navigate "about:blank"
            ie.Height=1900
            ie.Width=3300
            ie.Top=50
            ie.Left=50
            Do While ie.Busy
            WScript.Sleep 1000
            Loop
sa.minimizeall          
Function find_file

qc = vbNo
Do While qc =vbNo

Set Browsed = sa.BrowseForFolder(0, "Please select the folder.",4001, "")
If Not (Browsed Is Nothing) Then
Set BF=fs.GetFolder(browsed.self.path)
qc = MsgBox("That's Great. We're looking for files in "&vbCrLf&bf.Path&"!"&vbCrLf&"Is this correct",vbYesNo,"Is this the right folder?")
If bf.Files.Count=0 Then
qc = vbNo
d = MsgBox("There are no files in the dirctory chosen."&vbCrLf&"Please try again!",vbYesNo +vbExclamation,"Uh-Oh")
If d = vbNo Then ender
End if
Else
Call Ender
End If

Loop

ie.Visible=true
IE.Document.write "<body>The Files in " & bf.Path & " are:<br><br>"

For Each files In bf.Files
a = a & files.Name & "<br>"

Next
ie.Document.write "<div style='width:90%;height:70%;overflow:scroll;' id='mydiv'>"&a&"</div>"


rep1=InputBox("Great! What are we changing?","Text that should be replaced or removed from the file(s)","")
rep2=InputBox("Are we just erasing that or replacing it with something?","Replace or Erase text (Default is Erase)","")
ie.quit
c = MsgBox("Last question, just rename (Cannot undo!)",vbYesNo,"Rename or Duplicate Files with the New Names?")
MoveCopy c
ws.Popup "We're all done!"&vbCrLf&"Later!",4,"Job Well Done!"

Set ie = Nothing
Set fs = Nothing
Set ws = Nothing
sa.UndoMinimizeALL
Set sa = Nothing

WScript.Quit
End Function


find_file
Sub ender

ws.Popup "I thought we were working. My bad!"&vbCrLf&"Later!",4,"My Mistake"
ie.Quit
Set ie = Nothing
Set fs = Nothing
Set ws = Nothing
sa.UndoMinimizeALL
Set sa = Nothing

WScript.Quit
End Sub

function MoveCopy(c)

If c = vbNo Then
ws.Popup "Just a few moments.  We will create the renamed files in:" & vbCrLf & fs.GetAbsolutePathName(copied.Path) & vbCrLf &"Hold tight!",4,"Please wait..."
Set copied=fs.CreateFolder(".\Renamed")
Set copied=fs.getfolder(".\Renamed")
Else
ws.Popup "Just a few moments.  We will rename files in:" & vbCrLf & files.path & vbCrLf &"Hold tight!",4,"Please wait..."
End if

For Each files In bf.Files
aa = fs.GetBaseName(files)
bb = Replace(aa,rep1,rep2)
file2 = Replace(files.name,aa,bb)
Set dd = fs.getfile(files.Path)

If c = vbno Then


dd.Copy ".\Renamed\" & files2
else
fs.movefile dd.path, ".\"&files2


End If
Next
End function

vbscript
1个回答
1
投票

当未定义对象时,您有时会收到误导性的系统消息

This directory contains entries whose names differ only in case

关注实际错误很重要,在这种情况下,它是

object required 'Files'

对象的命名应该唯一,避免与保留字和其他对象冲突,如果要在单个子或函数之外使用,对象名称必须使用全局

Dim
定义,建议使用
Option Explicit
以避免错别字导致对象错误。

本例中的

Files
对象违反了大部分(如果不是全部的话)这些规则。

© www.soinside.com 2019 - 2024. All rights reserved.