• 0

Command Line Batch Script


Question

Hi all, i use this script to compress all .txt and .cpi files into the backup folder in separated files with 7zip. After the files are zipped i delete the original files. However this script has a logical flaw. Lets say if the 7zip program fails to run, the files will also get deleted. How can i change the script so that it should not delete the files if they don't get zipped first. Also how can i change this script so it zips files that are older than 7 days? Thanks for your help.

@echo off

setlocal

set _source=C:\test7zip\bak

set _dest=C:\test7zip\bak

set _wrpath=C:\Program Files\7-Zip

if NOT EXIST %_dest% md %_dest%

for %%I in (%_source%\*.txt,%_source%\*.cpi) do "%_wrpath%\7z" a "%_dest%\%%~nI.7z" "%%I" & del "%%I"

pause

Link to comment
https://www.neowin.net/forum/topic/1141312-command-line-batch-script/
Share on other sites

2 answers to this question

Recommended Posts

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

  • Recent Achievements

    • One Month Later
      Sopa flores earned a badge
      One Month Later
    • First Post
      StaticMatrix earned a badge
      First Post
    • Week One Done
      StaticMatrix earned a badge
      Week One Done
    • Rookie
      lamborghiniv10 went up a rank
      Rookie
    • One Month Later
      pinnclepd earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      504
    2. 2
      PsYcHoKiLLa
      207
    3. 3
      +Edouard
      155
    4. 4
      Steven P.
      87
    5. 5
      ATLien_0
      79
  • Tell a friend

    Love Neowin? Tell a friend!