kanine
kanine

Reputation: 65

Create a Timestamped ZIP Archive from Windows Command Prompt

I've made a simple script to create a timestamped zip archive using a combination of PowerShell and a DOS command, but is there a better way to do this just using a single PowerShell command with piping?

FOR /F "tokens=* USEBACKQ" %%F IN (`powershell get-date -format "{yyyymmdd-HHmmss}"`) DO (
SET ARCHTIMESTAMP=%%F
)

powershell Compress-Archive -Path yourpath -DestinationPath yourdestpath\yourname-%ARCHTIMESTAMP%.zip

Upvotes: 1

Views: 563

Answers (2)

krishnamoorthy R
krishnamoorthy R

Reputation: 52

back.bat:

@echo off
set datetime=%DATE%_%TIME:~-11,2%-%TIME:~-8,2%
set datetime=%datetime:/=-%
tar -acvf "D:\path_%datetime%.rar" "D:\foldername"

Upvotes: 0

alroc
alroc

Reputation: 28174

You're incredibly close with what you have here. Just drop the get-date in where you're creating the string for your destination path.

Compress-Archive -Path yourpath -DestinationPath "yourdestpath\yourname-$(get-date -format "{yyyyMMdd-HHmmss}").zip"

Upvotes: 2

Related Questions