Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: How to zip file one by one thru command line  (Read 3407 times)

0 Members and 1 Guest are viewing this topic.

mkn

  • Guest
How to zip file one by one thru command line
« on: December 23, 2009, 09:48:13 PM »
Hi

I am having trouble to managing my disk space.

Currently i am getting file in following format.

a_011209.txt
a_021209.txt
b_011209.txt
b_021209.txt

I want to create a batch file where it will prompt me to change the date from 011209( DDMMYY format) to 021209 and then compress these files one by one.

Thanks in advance for your help.

Manoj


BillRichardson



    Intermediate

    Thanked: 15
    Re: How to zip file one by one thru command line
    « Reply #1 on: December 28, 2009, 07:09:08 PM »


    C:\>compact  /?
    Displays or alters the compression of files on NTFS partitions.

    COMPACT [/C | /U] [/S[:dir]] [/A] [/I] [/F] [/Q] [filename [...]]

      /C        Compresses the specified files.  Directories will be marked
                so that files added afterward will be compressed.
      /U        Uncompresses the specified files.  Directories will be marked
                so that files added afterward will not be compressed.
      /S        Performs the specified operation on files in the given
                directory and all subdirectories.  Default "dir" is the
                current directory.
      /A        Displays files with the hidden or system attributes.  These
                files are omitted by default.
      /I        Continues performing the specified operation even after errors
                have occurred.  By default, COMPACT stops when an error is
                encountered.
      /F        Forces the compress operation on all specified files, even
                those which are already compressed.  Already-compressed files
                are skipped by default.
      /Q        Reports only the most essential information.
      filename  Specifies a pattern, file, or directory.

      Used without parameters, COMPACT displays the compression state of
      the current directory and any files it contains. You may use multiple
      filenames and wildcards.  You must put spaces between multiple
      parameters.

    C:\>
    Bill Richardson

    BillRichardson



      Intermediate

      Thanked: 15
      Re: How to zip file one by one thru command line
      « Reply #2 on: December 28, 2009, 07:36:07 PM »
      C:\>type  press.bat

      Code: [Select]
      @echo off

      sed s/011209/021209/  datfile.txt


      sed s/011209/021209/  datfile.txt  |  compact /c
      C:\>press.bat
      a_021209.txt
      a_021209.txt
      b_021209.txt
      b_021209.txt

       Setting the directory C:\ to compress new files [OK]

       Compressing files in C:\

      -------------------------
      rem Uncompress
      rem C:\>sed s/011209/021209/  datfile.txt  |  compact  /u
      Bill Richardson

      Geek-9pm


        Mastermind
      • Geek After Dark
      • Thanked: 1026
        • Gekk9pm bnlog
      • Certifications: List
      • Computer: Specs
      • Experience: Expert
      • OS: Windows 10
      Re: How to zip file one by one thru command line
      « Reply #3 on: December 28, 2009, 08:31:24 PM »
      Note: SED is just one of many UNIX or GNU things that have been redone for a Windows 32 bit environment.
      Look here, Sed is near the bottom of the list.
      http://unxutils.sourceforge.net/

      BillRichardson



        Intermediate

        Thanked: 15
        Re: How to zip file one by one thru command line
        « Reply #4 on: December 28, 2009, 08:53:44 PM »
        Note: SED is just one of many UNIX or GNU things that have been redone for a Windows 32 bit environment.
        Look here, Sed is near the bottom of the list.
        http://unxutils.sourceforge.net/

        I believe my sed version is for 32-bit and the creation date is 2005.

        The simple substitution(s) of one pattern in a file name for different pattern seems to work ok.

        sed s/011209/021209/  datfile.txt

        p.s. I have not used 64-bit

        Bill Richardson

        ghostdog74



          Specialist

          Thanked: 27
          Re: How to zip file one by one thru command line
          « Reply #5 on: December 28, 2009, 09:50:24 PM »
          Note: SED is just one of many UNIX or GNU things that have been redone for a Windows 32 bit environment.
          Look here, Sed is near the bottom of the list.
          http://unxutils.sourceforge.net/

          better to use GNU ones....see my sig

          Geek-9pm


            Mastermind
          • Geek After Dark
          • Thanked: 1026
            • Gekk9pm bnlog
          • Certifications: List
          • Computer: Specs
          • Experience: Expert
          • OS: Windows 10
          Re: How to zip file one by one thru command line
          « Reply #6 on: December 29, 2009, 12:10:13 AM »
          better to use GNU ones....see my sig
          Thanks, my beady little eyes did not see that before.
          Here is the link in big letters.
          http://gnuwin32.sourceforge.net/packages.html