[Function] FGP - FileGetProperties

Post your working scripts, libraries and tools
kon
Posts: 1760
Joined: 29 Sep 2013, 17:11

[Function] FGP - FileGetProperties

25 Jun 2014, 19:01

FGP - FileGetProperties
Functions for retrieving extended file properties.

Example Usage

Code: [Select all] [Expand] [Download] (FGP_Example.ahk)GeSHi © Codebox Plus


Functions

Code: [Select all] [Expand] [Download] (FGP.ahk)GeSHi © Codebox Plus


File properties numbers will vary depending on your system. This is the reason some functions generate a static look-up table.
Files will not necessarily have values for every property. i.e. The "Authors" property is used by some MSOffice files, but it is blank in the majority of other cases.

References

Change Log
Last edited by kon on 05 Jul 2014, 02:46, edited 3 times in total.
User avatar
joedf
Posts: 6337
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

Re: [Function] FGP - FileGetProperties

25 Jun 2014, 19:19

Providing an MSDN link or a list of properties would be great.
kon
Posts: 1760
Joined: 29 Sep 2013, 17:11

Re: [Function] FGP - FileGetProperties

25 Jun 2014, 20:33

I moved the reference URL's from the comments to actual links (much better, thanks joedf). Also, I added a bit of an explanation regarding property numbers varying.
User avatar
joedf
Posts: 6337
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

Re: [Function] FGP - FileGetProperties

25 Jun 2014, 21:10

Great! :D
kon
Posts: 1760
Joined: 29 Sep 2013, 17:11

Re: [Function] FGP - FileGetProperties

27 Jun 2014, 14:49

Some updates to the functions:
  • Added the FGP_List function to get all of a file's non-blank properties.
  • Changed FGP_Init's returned array to use a zero-based index.
  • Changed FGP_Num to use a look-up table instead of looping.
elmo
Posts: 54
Joined: 09 Oct 2013, 09:08

Re: [Function] FGP - FileGetProperties

27 Jun 2014, 16:39

Quite elegant. Thank you.
kon
Posts: 1760
Joined: 29 Sep 2013, 17:11

Re: [Function] FGP - FileGetProperties

05 Jul 2014, 02:50

Update:
  • Changed FGP_Init so that the other functions all contain static references to the same PropTable object instead of each function having its own array.
  • Replaced FGP_ByName and FGP_ByNum with the new function FGP_Value. The new function accepts either a property name or number as its second parameter and returns the property value.
  • Changed FGP_Name to return -1 instead of 0 in the event the property number does not have an associated name. The reason for the change is for consistency with FGP_Num. FGP_Num cannot return 0 as an error code because 0 is a valid property number.
jiggunjer
Posts: 13
Joined: 16 Jan 2016, 04:00

Re: [Function] FGP - FileGetProperties

18 Jan 2016, 22:40

can these properties be used to differentiate a compressed (e.g. zip/rar) from a 'normal' file (e.g. txt, jpeg, etc). The compressed field from the default "FileGetAttrib" is unreliable.
User avatar
joedf
Posts: 6337
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

Re: [Function] FGP - FileGetProperties

18 Jan 2016, 23:33

Well, you could have a custom function to check for the "file magic number" and determine zip and rar, etc
lexikos
Posts: 5981
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: [Function] FGP - FileGetProperties

19 Jan 2016, 00:27

The compressed field from the default "FileGetAttrib" is unreliable.
The "Compressed" attribute is about file system compression, not about what type of data the file contains. It's the "Compress contents to save disk space" option in the file's properties, under "Advanced". Usually names of compressed files are displayed with blue text in Explorer.

Windows does not "know" about all compressed file types natively, and it's doubtful that all of the different archiving programs mark the file in some way that's common between file types. So if you want to identify whether a file is a compressed archive or not, you need to know about each file type (filename extension or some signature within the data). Or you could utilize an external program or library, like the 7-zip DLL.
JoeWinograd
Posts: 970
Joined: 10 Feb 2014, 20:00

Re: [Function] FGP - FileGetProperties

01 Feb 2018, 15:58

Hi kon,
First, I want to thank you very much for FGP. It has solved a nasty problem for me, namely, to create a count of all the pages in all the PDF files in a folder (and, optionally, its subfolders). I had been using a utility that requires opening a PDF to determine its page count and, of course, it was failing on all of the password protected PDFs. Your fantastic FGP does not suffer from that!

But I am having one problem that I hope you can help me to troubleshoot. I'm using just FGP_Value (which, of course, calls FGP_Init). I've tried both FGP_Value(FilePath,"Pages") and FGP_Value(FilePath,148) — both work perfectly. I haven't modified your functions. Here's my simple test code calling it:

Code: [Select all] [Download] GeSHi © Codebox Plus

#NoEnv
SetBatchLines,-1
FileSelectFile,FilePath
PropValPages:=FGP_Value(FilePath,148)
MsgBox % PropValPages
ExitApp

I'm using it just on PDF files. It works perfectly on some computers, returning the number of pages in the PDF, but fails on others, returning 0. The machines are a mixture of W7 and W10, Home and Pro, all 64-bit. In some cases, I'm running from source code with AHK 1.1.27.07 U32; in other cases, I'm running the EXE (compiled with AHK 1.1.27.07 U32). But I'm pretty sure none of that matters. I think the issue has to do with the properties of the PDF files not being exposed due to the absence of something PDF-related on the machines where it fails. I don't think that this is an FGP issue, but I'm wondering if you've seen this before and can point me to the reason why FGP is not able to retrieve the number of pages in a PDF file. Thanks much, Joe

Update: There's a good discussion going on in this thread. Please have a look when you get a chance. Thanks!

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 14 guests