Script error when browsing folders

I have script to display CHMOD for ftp files.
Each time I change folder, I have this error...

mer. 18/12/2024 10:32:58 Colonne_CHMOD: Erreur à la ligne 24, position 2
mer. 18/12/2024 10:32:58 Colonne_CHMOD: Objet requis: 'scriptColData.tab' (0x800a01a8)

Can you help me please

option explicit

Function OnInit(initData)
	initData.name = "Colonne_CHMOD"
	initData.desc = "Ajoute une colonne 'CHMOD' pour afficher les permissions FTP."
	initData.copyright = "2016 Albator V (Michiels Thomas)"
	initData.min_version = "12.0.7"	
	initData.version = "1.0"
	InitData.group = "Colonne"
	initData.default_enable = True
End Function

Function OnAddColumns(addColData)
	Dim col: Set col = addColData.AddColumn
	col.name = "CHMOD"
	col.method = "OnCHMOD"
	col.autorefresh = 2
	col.justify = "center"
End Function

Function OnCHMOD(scriptColData)
	Dim CHMOD, i

	If Left(scriptColData.tab.path, 6) = "ftp://" And Len(Trim(scriptColData.item.attr_text)) = 10 Then
		CHMOD = Trim(scriptColData.item.attr_text)
' remplace les lettres par des 1
		For i = 1 to Len(CHMOD)
			If Mid(CHMOD, i, 1) <> "-" Then CHMOD = Replace(CHMOD, Mid(CHMOD, i, 1), 1)
		Next
' remplace les tirets par des 0
		CHMOD = Replace (CHMOD, "-", 0)
' conversion en binaire
		CHMOD = BinaryToDecimal(Mid(CHMOD, 2, 3)) & BinaryToDecimal(Mid(CHMOD, 5, 3)) & BinaryToDecimal(Mid(CHMOD, 7, 3))
	Else
		CHMOD = "---"
	End If	
	scriptColData.value = CHMOD
End Function

Function BinaryToDecimal(Binary)
	Dim n, s

	For s = 1 To Len(Binary)
		n = n + (Mid(Binary, Len(Binary) - s + 1, 1) * (2 ^ (s - 1)))
	Next
	BinaryToDecimal = n
End Function

.path returns an object, not a string.

1 Like

Thanks
How to retreive the current path ?

You can convert the path with CStr().

1 Like

Many thanks

Not really solved :neutral_face:
Now, no error when browsing folders but same errors when I start Dopus.

If CStr(Left(scriptColData.tab.path, 6)) And... 

You were close :slight_smile:

If Left(CStr(scriptColData.tab.path), 6) = "ftp://" And...

I have already tried with this... but errors when opening Opus and when browsing folders.

Ah, yes... but that's for a different reason.

That will happen when navigating to nodes like "This PC". In this case, the script will be called with an empty or uninitialized tab or tab.path.

You can test this with IsEmpty() and IsNull(). One test might be sufficient, but I don't know VBscript well enough to be sure.

Alternatively, you could use PathType():

Returns a string indicating the underlying "namespace" type of the specified file path.

FSUtil


The EverythingFolderSize add-in contains many tests to cover all situations. It's in JScript, but you'll get the idea.


Actually, there was nothing wrong with

If Left(scriptColData.tab.path, 6) = "ftp://"

Left() handles the path object with no problem, no CStr() is needed. Sorry!

I still haven't found a solution to avoid error messages when opening DOPUS and when I navigate through folders.
@Leo, any idea ?

 lun. 06/01/2025 10:51:44 Colonne_CHMOD:  Erreur à la ligne 23, position 2
 lun. 06/01/2025 10:51:44 Colonne_CHMOD:  Objet requis: 'scriptColData.tab' (0x800a01a8)

(I update my script to use regex to replace characters and use FSUtil to check ftp folder)

option explicit

Function OnInit(initData)
	initData.name = "Colonne_CHMOD"
	initData.desc = "Ajoute une colonne 'CHMOD' pour afficher les permissions FTP."
	initData.copyright = "2025 Albator V (Michiels Thomas)"
	initData.min_version = "12.0.7"	
	initData.version = "2.0"
	InitData.group = "Colonne"
	initData.default_enable = True
End Function

Function OnAddColumns(addColData)
Dim col: Set col = addColData.AddColumn
	col.name = "CHMOD"
	col.method = "OnCHMOD"
	col.autorefresh = 2
	col.justify = "center"
End Function

Function OnCHMOD(scriptColData)
Dim CHMOD, objRegExp
	If NOT IsEmpty(scriptColData.tab.path) Then
		If DOpus.FSUtil.PathType(scriptColData.tab.path) = "ftp" And Len(Trim(scriptColData.item.attr_text)) = 10 Then
			CHMOD = Trim(scriptColData.item.attr_text)
	' remplace les lettres par des 1
			Set objRegExp = New RegExp
			objRegExp.Global = True					' Remplacer toutes les occurrences
			objRegExp.IgnoreCase = True				' Ignorer la casse (optionnel)
			objRegExp.Pattern = "[a-zA-Z]"			' Expression régulière pour les lettres
			CHMOD = objRegExp.Replace(CHMOD, "1")
	' remplace les tirets par des 0
			objRegExp.Pattern = "-"
			CHMOD = objRegExp.Replace(CHMOD, "0")
	' conversion en binaire
			CHMOD = BinaryToDecimal(Mid(CHMOD, 2, 3)) & BinaryToDecimal(Mid(CHMOD, 5, 3)) & BinaryToDecimal(Mid(CHMOD, 7, 3))
		Else
			CHMOD = "---"
		End If
	End If
	scriptColData.value = CHMOD
End Function

Function BinaryToDecimal(Binary)
Dim n, s
	For s = 1 To Len(Binary)
		n = n + (Mid(Binary, Len(Binary) - s + 1, 1) * (2 ^ (s - 1)))
	Next
	BinaryToDecimal = n
End Function

Erreur à la ligne 23, position 2

Line 23: If NOT IsEmpty(scriptColData.tab.path) Then

Based on what Lxp said above, it'd be worth testing the scriptColData.tab object before trying to access the path property below it.

(Remember that VBScript is a bad language and you have to do the two tests separately, not part of a single if-statement, or it'll still go wrong.)