Menu

Please add a switch to generate archive name YYYYMMDDHHMMSS using the current date and time

PiotrMP006
2023-06-01
2023-06-02
  • PiotrMP006

    PiotrMP006 - 2023-06-01

    Please add a switch to generate archive name YYYYMMDDHHMMSS using the current date and time

    ex.

    archiveYYYYMMDDHHMMSS.7z
    archive20230601012543.7z

     
  • Elias Fotinis

    Elias Fotinis - 2023-06-02

    That's indeed very useful, but I doubt it should be added to the core program. Assuming we're talking about the command line, why not create a function/alias in your terminal of choice? For example, in Windows/PowerShell I have a Get-FileNameSafeTimestamp function aliased to fst that returns exactly that. So, typing 7z.exe a "archive-$(fst).7z" * will add all current files to archive-20230602T1059340252.7z. My implementation is:

    # Timestamp in filename-safe format.
    function Get-FileNameSafeTimestamp ([switch]$Utc, [switch]$DateOnly) {
        $fmt = 'FileDate'
        if (-not $DateOnly) { $fmt += 'Time' }
        if ($Utc) { $fmt += 'Universal' }
        Get-Date -Format $fmt
    }
    

    Not to mention that this way also makes it available to any program. :)

     

Log in to post a comment.