Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 373285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:17:36+00:00 2026-05-12T14:17:36+00:00

I am actually pretty new to this batch file thing. I know it’s important

  • 0

I am actually pretty new to this batch file thing. I know it’s important to know at least the basic commands. How do I do the following?

  • Zipping a specified folder.
  • Move the folder to another place.
  • When zipping it, the ZIP file name will be the current date and
    if there is another zipped file with the same name, it should be named like 20090924-2.

PS: 7-Zip is installed on my computer as an archive software.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T14:17:36+00:00Added an answer on May 12, 2026 at 2:17 pm

    The batch script listed below will do it (I have tested it
    and it works to specifications). The directory to zip and
    move is specified as its parent directory and the name of
    the directory (PARENT_FOLDERTOZIP and FOLDERTOZIP in the
    beginning) – I couldn’t figure out how to copy entire
    directories (I think XCOPY can only copy content of
    directories and sub-directories.). The copy location is
    specified as FOLDERTARGETLOCATION, and the directory to place
    the compressed files in is specified as ZIPDIR.

    The location of 7-Zip is configured through SEVENZIP_EXE.

    Note also that getting the current date in the required
    format depends on the short date format in regional
    settings. I have listed three different versions for
    ISO-8601, Central European and U.S.A. The active one in the
    listing is for the U.S.A. (the “set FDATE=” line). If a
    different one is needed then just copy-paste from one of the
    other two.

    That said it should be noted that this kind of thing is much
    easier with Perl, Python or PowerShell.


    @echo off
    @title=Folder zip and move...
    
    rem Parameters
      rem Folder to zip and move
        set PARENT_FOLDERTOZIP=T:\to delete
        set FOLDERTOZIP=Folder to Compress
    
      rem Target folder for moving the input folder to.
        set FOLDERTARGETLOCATION=s:\move Here
    
      rem Where to place compressed folders
        set ZIPDIR=D:\toDelete\2009-09-24a
    
    
    rem Configuration
      set SEVENZIP_EXE=D:\Program Files\7-Zip\7z.exe
    
    
    rem =================== Date ==============================================
    rem There is no universal way inside batch itself to get a
    rem date that is independent of regional settings (but is
    rem quite trivial if an external program or script
    rem (Perl/Python) is available).
    rem
    rem For short date formats:
    rem
    rem   -------------------------------------------------------
    rem
    rem   ISO-8601:
    rem     0123456789
    rem     yyyy-MM-dd/     E.g.: 2009-09-24
    rem
    rem     set FDATE=%DATE:~0,4%%DATE:~5,2%%DATE:~8,2%
    rem
    rem   -------------------------------------------------------
    rem
    rem   Central european:
    rem     0123456789
    rem     dd/MM/yyyy     E.g.: 24/09/2009
    rem
    rem     set FDATE=%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%
    rem
    rem   -------------------------------------------------------
    rem
    rem   US:
    rem
    rem     0123456789
    rem     MM/dd/yyyy     E.g.: 09/24/2009
    rem
    rem     set FDATE=%DATE:~6,4%%DATE:~0,2%%DATE:~3,2%
    
    set FDATE=%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%
    set ZIPFILE=%ZIPDIR%\%FDATE%.7z
    
    set FOLDERTOZIP_FULLPATH=%PARENT_FOLDERTOZIP%\%FOLDERTOZIP%
    mkdir %FOLDERTARGETLOCATION%
    
    
    rem Does a zip file already exist?
    if exist "%ZIPFILE%" GOTO L_ZIPFILE_EXISTS
    GOTO L_ZIPFILENAME_OK
    
    
    rem Find a compressed file that does not already exist.
    :L_ZIPFILE_EXISTS
    set RNUM=0
    :L_TRYANOTHER
    set /a RNUM=%RNUM% + 1
    set ZIPFILE=%ZIPDIR%\%FDATE%-%RNUM%.7z
    echo Candidate: %ZIPFILE% ...
    if exist "%ZIPFILE%" GOTO L_TRYANOTHER
    
    
    rem Zip the folder!
    :L_ZIPFILENAME_OK
    "%SEVENZIP_EXE%"  a %ZIPFILE%   "%FOLDERTOZIP_FULLPATH%"
    
    if exist "%ZIPFILE%" GOTO L_OKZIP
    GOTO L_ERROREND
    
    
    :L_OKZIP
    rem Move folder: copy, then delete source.
    set DEST_FOLDER=%FOLDERTARGETLOCATION%\%FOLDERTOZIP%
    mkdir "%DEST_FOLDER%"
    xcopy /Y /S "%FOLDERTOZIP_FULLPATH%"\*.*   "%DEST_FOLDER%"\
    rmdir /S "%FOLDERTOZIP_FULLPATH%"
    GOTO L_END
    
    
    :L_ERROREND
    echo 7-Zipping failed !!!
    
    
    :L_END
    
    pause
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 309k
  • Answers 309k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Following is a generic RadioGroupBox implementation in the spirit of… May 13, 2026 at 10:03 pm
  • Editorial Team
    Editorial Team added an answer Yes if you modify your Create function to take a… May 13, 2026 at 10:03 pm
  • Editorial Team
    Editorial Team added an answer You're trying to get an item from a list (or… May 13, 2026 at 10:03 pm

Related Questions

I am actually pretty new to this batch file thing. I know it's important
I am pretty new to silverlight and was very surprised to see that only
I have a minor problem where my (new) computer tends to completely freeze up.
I have inherited some code: Process p = new ProcessBuilder(/bin/chmod, 777, path).start(); p.waitFor(); Basically,
I am using Python Mechanize to open a website, fill out a form, and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.