Error using is_dir in script

windows 10 64-bit 简体中文, Directory Opus 12.3 12.4 Had this problem

If Not CompareData.Item.is_dir Then
DOpus.FSUtil.GetItem(FilePath).modify
 2017/3/24 16:01 Column Collection:  发生错误于 207,位置 13
 2017/3/24 16:01 Column Collection:  对象不支持此属性或方法: 'is_dir' (0x800a01b6)
 2017/3/24 20:36 Column Collection:  发生错误于 364,位置 24
 2017/3/24 20:36 Column Collection:  对象不支持此属性或方法: 'access' (0x800a01b6)

Use this code to complete the same job the error does not occur, why the hell is this?

Function GetDate(ByVal Path, ByVal DateType)
	Dim FSO,Item
    Set FSO = CreateObject("Scripting.FileSystemObject")
	If FSO.FileExists(Path) Then
		Set Item = FSO.GetFile(Path)
	ElseIf FSO.FolderExists(Path) Then
		Set Item = FSO.GetFOlder(Path)
	Else
		GetDate = 0
	End If
	If IsObject(Item) then
		Select Case LCase(DateType)
			Case "a"
				GetDate = Item.DateLastAccessed
			Case "c"
				GetDate = Item.DateCreated
			Case "m"
				GetDate = Item.DateLastModified
		End Select
		Set Item = Nothing
	End If
	Set FSO = Nothing
End Function

Function GetType(ByVal Path)
    With CreateObject("Scripting.FileSystemObject")
        Path = .GetAbsolutePathName(Path)
        Select Case True
            Case .FileExists(Path)   : GetType = 1
            Case .FolderExists(Path) : GetType = 2
            Case Else                : GetType = 0
        End Select
    End With
End Function

Function Is_File(ByVal Path)
    Is_File = (GetType(Path) = 1)
End Function

Function Is_Folder(ByVal Path)
    Is_Folder = (GetType(Path) = 2)
End Function

Function Is_Exists(ByVal Path)
    Is_Exists = (GetType(Path) <> 0)
End Function

Where is CompareData from?

	Set col = initData.AddColumn
	col.name = "IsEmptyFile"
	col.method = "OnCompare"
	col.label = "Is Empty File"
    col.header = "空文件"
	col.justify = "center"
	col.autogroup = True
    col.match.push_back(CStr(True))
    col.match.push_back("")
Function OnCompare(CompareData)
    Select Case CompareData.Col
        Case "IsModified"
            If Not CompareData.Item.is_dir Then 'Is_File(CompareData.Item)
                If CompareData.Item.Create = CompareData.Item.Modify Then
                    CompareData.Sort = 2
                Else
                    CompareData.value = Cstr(True)
                    CompareData.Sort = 1
                End If
            Else
                CompareData.Sort = 0
            End If
        Case "IsEmptyFile"
            'If Is_File(CompareData.Item) Then
            If Not CompareData.Item.is_dir Then 
                If CompareData.Item.size = 0 Then CompareData.value = CStr(True)
            End If
    End Select                    
End Function

这段代码中第一次出现的item.is_dir总也不出错,第二个就总报错。

        Select Case LCase(DType)
            Case "a" : FileDate = DOpus.FSUtil.GetItem(FilePath).access : GroupText = "访问于 "
            Case "c" : FileDate = DOpus.FSUtil.GetItem(FilePath).create : GroupText = "创建于 "
            Case "m" : FileDate = DOpus.FSUtil.GetItem(FilePath).modify : GroupText = "修改于 "
        End Select

这段代码在单位的电脑中就没问题,但是回到家里就出错了。单位用的是12.4,家里用的是12.3,都是windows 10 64-bit。Column Collection.vbs.txt (36.4 KB)

I translated above Chinese words for you guys discuss better.
That code I uploaded run corrent in my office computer,but get error in my home PC.The version of Doups in my office is 12.4,home version is 12.3.OS are win10 X64 both.

1 Like

If the home computer is updated to the latest version, does it work then?

If not, it looks like something that might be caused by something in a particular folder. If you can work out which folder(s) it happens in, and see if there is anything special about them, that should help us work out what is going wrong.

For example, if it only happens when you view the Desktop folder, it might be due to the special This PC item in that folder, if it is turned on.

Any folder by pressing F5 will appear this error

Find out why

Function OnGetAge(AgeColData)
    DOpus.Output AgeColData.item & " : " & CBool(DOpus.FSUtil.Exists(AgeColData.item))
End Function
 2017/3/25 17:18 Column Collection:  C:\Users\qiuqiu\Desktop : True
 2017/3/25 17:18 Column Collection:  C:\Users\qiuqiu\Downloads : True
 2017/3/25 17:18 Column Collection:  C:\Users\qiuqiu\Downloads : True
 2017/3/25 17:18 Column Collection:  C:\Users\qiuqiu\Documents : True
 2017/3/25 17:18 Column Collection:  C:\Users\qiuqiu\Pictures : True
 2017/3/25 17:18 Column Collection:  C:\Users\qiuqiu\Desktop\球球 : False
 2017/3/25 17:18 Column Collection:  C:\Users\qiuqiu\Desktop\OneDrive : False
 2017/3/25 17:18 Column Collection:  C:\ : True
 2017/3/25 17:18 Column Collection:  D:\ : True
 2017/3/25 17:18 Column Collection:  C:\ : True
 2017/3/25 17:18 Column Collection:  D:\ : True
 2017/3/25 17:18 Column Collection:  C:\Users\qiuqiu\Desktop : True
 2017/3/25 17:18 Column Collection:  C:\Users\qiuqiu\Downloads : True
 2017/3/25 17:18 Column Collection:  C:\Users\qiuqiu\Documents : True
 2017/3/25 17:18 Column Collection:  C:\Users\qiuqiu\Pictures : True
 2017/3/25 17:18 Column Collection:  C:\ : True
 2017/3/25 17:18 Column Collection:  D:\ : True
 2017/3/25 17:18 Column Collection:  C:\Users\qiuqiu\Desktop\球球 : False
 2017/3/25 17:18 Column Collection:  C:\Users\qiuqiu\Desktop\OneDrive : False
 2017/3/25 17:18 Column Collection:  C:\ : True
 2017/3/25 17:18 Column Collection:  D:\ : True

Why are there item that do not exist?

...
 2017/3/25 17:18 Column Collection:  C:\Users\qiuqiu\Desktop\球球 : False
 2017/3/25 17:18 Column Collection:  C:\Users\qiuqiu\Desktop\OneDrive : False

Those are just things that don't exist in the real filesystem but are shown in virtual folders like Desktop. Nothing unusual there.

An exception is generated

dopus.output DOpus.FSUtil.GetItem("C:\Users\qiuqiu\Desktop\OneDrive").access

"C:\Users\qiuqiu\Desktop\OneDrive" is not a real file or folder. It does not exist on disk.

  • Have a look in "C:\Users\qiuqiu\Desktop" and you will not see a "OneDrive" file or folder. It isn't there.
  • If you look in your virtual Desktop folder, you may see a OneDrive item in there, which links to a folder somewhere else.
  • The virtual Desktop folder also shows you the things in "C:\Users\qiuqiu\Desktop".
  • The virtual Desktop folder also shows you the things in "C:\Users\Public\Desktop".
  • The virtual Desktop folder is not the same as "C:\Users\qiuqiu\Desktop". They are two different things. The virtual folder does not exist on disk; it combines various folders and items into a view that shows them all at once. Some of things do exist on disk, in different places. If you use the virtual folder in a context that needs a real folder path, it will usually turn into "C:\Users\qiuqiu\Desktop" as that is the best approximation, but the two things are not the same.

If you pass "C:\Users\qiuqiu\Desktop\OneDrive" to FSUtil.GetItem it will fail, because "C:\Users\qiuqiu\Desktop\OneDrive" does not exist. FSUtil.GetItem won't return an object in this case.

If you try to call .access on the result, you'll get an exception, because the result is not an object and has no .access method or property.

Nothing wrong or surprising here. And nothing that would happen in "any folder by pressing F5"; this is all specific to the Desktop virtual folder, at least so far.