GP Software ā€¢ Twitter
Opus FAQs ā€¢ Manual ā€¢ Commands ā€¢ Objects

Real File Type / Extension

I just realized I accidentally removed the extension for hundreds of files in a folder at some point in time. And I remembered how Amiga was conveniently able to provide real file type regardless of the extension or even lack of one. :slight_smile:

So, I wonder if Opus is capable of this or it solely leans on the file extension to determine the file type?

For some file types.

Try the Description column.

Already tried no go. These are either rar or zip archives. That much I know. :slight_smile:

I believe it is possible, but I guess it would too slow...

I don't think we do it for those file types. It's mainly done for images.

You could write a simple script column that looks for the Zip or RAR header at the start of every file.

Thanks for the hint, I'm on it. More new things to learn. :slight_smile:

Opus has a Blob object to help scripts read and process raw binary data, since it's often not something the scripting languages are good at.

Depending on how accurate you want to make the column, you could just look at the first few bytes to see if they have the "magic values" at the start of Zip and RAR files. Parsing the header more to get more accurate results is also possible, but maybe more work than it's worth, depending on what you're aiming for.

I am not too ambitious about the accuracy, at least not at this moment.Here is the quick win that works. I believe it's not too efficient since I was not using blob object. I still need to figure out how to use it. On the other hand there are couple of unreadable characters at the end and this would need to be taken care of, as well as the plain text file that I would need to somehow prefilter and exclude from the processing.

In another words - this works but it's very spartan and not for further publishing. :slight_smile:

Spartan solution:

Function ReadRealExtensionFromHeader(scriptColData)
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, f2read

 If scriptColData.col <> "RealFTExt" Then Exit Function
 If scriptColData.item.is_dir Then scriptColData.value = ""
 
 Set fso = CreateObject("Scripting.FileSystemObject")
 Set f2read = fso.OpenTextFile( scriptColData.item.realpath, ForReading)
 scriptColData.value = f2read.Read(5)
 
End Function

Example result:

1 Like

Ok, I got it now with blobs and all. Thanks a thousands muchas gracias for a challenge push @Leo. :slight_smile:
I will post entire solution over to the scripting area and link here.

Here is the essence:

 Set f2R = scriptColData.item.Open 
 lngMxBlbLen = Iif(Clng(f2R.size) > HeaderMaxDepth, HeaderMaxDepth, f2R.size) - 2
 If lngMxBlbLen < 2 Then Exit Function
 f2R.Seek 0, "b"
 Set blbB = f2R.Read(lngMxBlbLen)
  
 lngI = 0
 strRE = ""
 Do While (blbB(lngI) > 31 And blbB(lngI) < 127) And (lngI < lngMxBlbLen)
  strRE = strRE & Chr(blbB(lngI))
  lngI =lngI + 1
 Loop
 If blbB(lngI) = 13 And blbB(lngI+1) = 10 Then lngI = lngMxBlbLen
 scriptColData.value = IIf(lngI = lngMxBlbLen, "", strRE)
1 Like

Ok, and here the very final solution:

1 Like

Hmm, hmm... it seems the script gets back an error it the file is in use. Any idea how to prevent that? Can the file be tested if it is locked for writing or maybe trap an error?

You probably only care about second half (item.Open without "we"), but here's how to check if a file is writable, or readable, or neither in a VBscript column:

function OnLocked(scriptColData)
{
	if (scriptColData.item.is_dir)
	{
		return;
	}
	
	var file = scriptColData.item.Open("we","ElevateNoAsk");
	var openError = file.error;
	file.Close();
	if (openError == 0)
	{
		scriptColData.value = "Writable";
		return;
	}

	file = scriptColData.item.Open("","ElevateNoAsk");
	openError = file.error;
	file.Close();
	if (openError == 0)
	{
		scriptColData.value = "Read-Only";
		return;
	}

	scriptColData.value = "Inaccessible";
}
1 Like