fileinfo

package module
v0.0.0-...-82a7647 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2025 License: MIT Imports: 10 Imported by: 0

README

fileinfo

fileinfo is a Go module for retrieving file version and file time information on Windows.

Installation

To install the module, use go get:

go get github.com/miroslav-matejovsky/wintoolkit/fileinfo

Usage

Retrieving File Version Information

You can retrieve the file version information using the fileinfo struct.

package main

import (
    "fmt"
    "log"

    "github.com/miroslav-matejovsky/wintoolkit/fileinfo"
)

func main() {
    file := `C:\Windows\System32\notepad.exe`
    wf, err := fileinfo.NewWinFile(file)
    if err != nil {
        log.Fatalf("Error creating WinFile: %v", err)
    }

    fi, err := wf.GetFileInfo()
    if err != nil {
        log.Fatalf("Error getting file info: %v", err)
    }

    fmt.Printf("File Version: %s\n", fi.FileVersion)
    fmt.Printf("Product Version: %s\n", fi.ProductVersion)
}
Retrieving File Time Information

You can retrieve the file time information using the WinFileTime struct.

package main

import (
    "fmt"
    "log"

    "github.com/miroslav-matejovsky/wintoolkit/fileinfo"
)

func main() {
    file := `C:\Windows\System32\notepad.exe`
    wf, err := fileinfo.NewWinFile(file)
    if err != nil {
        log.Fatalf("Error creating WinFile: %v", err)
    }

    ft, err := wf.GetFileTime()
    if err != nil {
        log.Fatalf("Error getting file time: %v", err)
    }

    fmt.Printf("Creation Time: %s\n", ft.CreationTime)
    fmt.Printf("Last Access Time: %s\n", ft.LastAccessTime)
    fmt.Printf("Last Write Time: %s\n", ft.LastWriteTime)
}

Testing

To run the tests, use the go test command:

go test ./...

License

This project is licensed under the MIT License. See the LICENSE file for details.

Documentation

Overview

package fileinfo provides utilities for retrieving file information on Windows systems.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Certificates

type Certificates struct {
	Certificates []*x509.Certificate
}

func (*Certificates) SignedBy

func (c *Certificates) SignedBy(verifier string) bool

func (*Certificates) ValidAtSignedBy

func (c *Certificates) ValidAtSignedBy(verifier string, at time.Time) bool

type FileTime

type FileTime struct {
	CreationTime   time.Time
	LastAccessTime time.Time
	LastWriteTime  time.Time
}

type Versions

type Versions struct {
	FileVersion    WinFileVersion
	ProductVersion WinFileVersion
}

type WinFileInfo

type WinFileInfo struct {
	// contains filtered or unexported fields
}

WinFileInfo represents a file on the Windows filesystem. This file must exist in the OS afero in memory cannot be used because native Windows APIs are used to retrieve file information.

func NewWinFileInfo

func NewWinFileInfo(path string) (*WinFileInfo, error)

NewWinFileInfo creates a new WinFile for the given path. It returns an error if the file does not exist or if there is an error checking the file.

func (*WinFileInfo) GetCertificates

func (wf *WinFileInfo) GetCertificates() (*Certificates, error)

GetCertificates retrieves the embedded certificates from the file. It returns a slice of x509.Certificate pointers or an error if the operation fails.

func (*WinFileInfo) GetFileTime

func (wf *WinFileInfo) GetFileTime() (*FileTime, error)

GetFileTime retrieves the file time information for the file. It returns a WinFileTime struct containing the file time information.

func (*WinFileInfo) GetFixedFileInfo

func (wf *WinFileInfo) GetFixedFileInfo() (*windows.VS_FIXEDFILEINFO, error)

GetFixedFileInfo retrieves the fixed file information for the file. It returns a windows.VS_FIXEDFILEINFO struct containing the fixed file information.

func (*WinFileInfo) GetVersions

func (wf *WinFileInfo) GetVersions() (*Versions, error)

GetVersions retrieves the file version information for the file. It returns a WinFileInfo struct containing the file version information.

type WinFileVersion

type WinFileVersion struct {
	Major uint16
	Minor uint16
	Patch uint16
	Build uint16
}

func (WinFileVersion) String

func (f WinFileVersion) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL