Skip to content

WindowsFileInfoCommand

Base classes

Name Children Inherits
FileInfoCommand
anyenv.os_commands.base
Base class for file info commands.

⋔ Inheritance diagram

graph TD
  25597700["file_info.WindowsFileInfoCommand"]
  3903279879["base.FileInfoCommand"]
  925645236["abc.ABC"]
  2751680898["builtins.object"]
  3903279879 --> 25597700
  925645236 --> 3903279879
  2751680898 --> 925645236

🛈 DocStrings

Bases: FileInfoCommand

Windows file info command implementation.

Source code in src/anyenv/os_commands/file_info.py
class WindowsFileInfoCommand(FileInfoCommand):
    """Windows file info command implementation."""

    def create_command(self, path: str) -> str:
        """Generate PowerShell file info command.

        Args:
            path: Path to get information about

        Returns:
            The PowerShell command string
        """
        return powershell(
            f"$item = Get-Item -LiteralPath {ps_literal(path)} -ErrorAction Stop; "
            "$item.Name + '||' + $item.Length + '||' + "
            "($item.GetType().Name) + '||' + "
            "[int][double]::Parse($item.LastWriteTime.ToString('yyyyMMddHHmmss'))"
        )

    def parse_command(self, output: str, path: str) -> FileInfo:
        """Parse PowerShell output format: name||size||type||mtime.

        Args:
            output: Raw PowerShell command output
            path: Original path requested

        Returns:
            FileInfo object with parsed information
        """
        parts = output.strip().split("||")
        if len(parts) < EXPECTED_POWERSHELL_PARTS:
            msg = f"Unexpected PowerShell output format: {output}"
            raise ValueError(msg)

        file_type: Literal["file", "directory", "link"] = (
            "directory" if "directory" in parts[2].lower() else "file"
        )

        return FileInfo(
            name=parts[0],
            path=path,
            type=file_type,
            size=int(parts[1]) if parts[1].isdigit() else 0,
            mtime=int(parts[3]) if parts[3].isdigit() else 0,
        )

create_command

create_command(path: str) -> str

Generate PowerShell file info command.

Parameters:

Name Type Description Default
path str

Path to get information about

required

Returns:

Type Description
str

The PowerShell command string

Source code in src/anyenv/os_commands/file_info.py
def create_command(self, path: str) -> str:
    """Generate PowerShell file info command.

    Args:
        path: Path to get information about

    Returns:
        The PowerShell command string
    """
    return powershell(
        f"$item = Get-Item -LiteralPath {ps_literal(path)} -ErrorAction Stop; "
        "$item.Name + '||' + $item.Length + '||' + "
        "($item.GetType().Name) + '||' + "
        "[int][double]::Parse($item.LastWriteTime.ToString('yyyyMMddHHmmss'))"
    )

parse_command

parse_command(output: str, path: str) -> FileInfo

Parse PowerShell output format: name||size||type||mtime.

Parameters:

Name Type Description Default
output str

Raw PowerShell command output

required
path str

Original path requested

required

Returns:

Type Description
FileInfo

FileInfo object with parsed information

Source code in src/anyenv/os_commands/file_info.py
def parse_command(self, output: str, path: str) -> FileInfo:
    """Parse PowerShell output format: name||size||type||mtime.

    Args:
        output: Raw PowerShell command output
        path: Original path requested

    Returns:
        FileInfo object with parsed information
    """
    parts = output.strip().split("||")
    if len(parts) < EXPECTED_POWERSHELL_PARTS:
        msg = f"Unexpected PowerShell output format: {output}"
        raise ValueError(msg)

    file_type: Literal["file", "directory", "link"] = (
        "directory" if "directory" in parts[2].lower() else "file"
    )

    return FileInfo(
        name=parts[0],
        path=path,
        type=file_type,
        size=int(parts[1]) if parts[1].isdigit() else 0,
        mtime=int(parts[3]) if parts[3].isdigit() else 0,
    )

:fa-brands-github: Show source on GitHub