none
Windows Batch Scripting RRS feed

  • Question

  • HI GUYS,

    i am making a batch script which contain my backup files+hashing+ compressing.

    my script working HASHING things 

    my question is I have 24 files and i want each 24 files to be ZIP separately.

    I dont want my file 24 file to zip together. Thanks please reply

    Example:

    file1.txt  ==> file1.7z

    file2.txt  ==> file2.7z

    file3.txt  ==> file3.7z

    • Moved by Bill_Stewart Wednesday, September 13, 2017 9:10 PM This is not "scripts on demand"
    Tuesday, July 25, 2017 4:43 PM

All replies

  • Get-ChildItem *.txt |
    	ForEach-Object{
    	     7z add "$($_.Fullname).7z" $($_.Fullname)
    	}
    


    \_(ツ)_/

    Tuesday, July 25, 2017 4:59 PM
  • If you install the 7zip PowerShell module

    Find-Module 7Zip4Powershell | Install-Module

    You can do this.

    Import-Module 7Zip4Powershell
    Get-ChildItem *.txt |
    	ForEach-Object{
    	     Compress-7zip -Archive "$($_.Fullname).7z" -Path $_.Fullname
    	}


    \_(ツ)_/

    Tuesday, July 25, 2017 5:09 PM
  • If you want to keep it batch

    a for loop would iterate the files in the folder then compress.

    https://ss64.com/nt/for.html

    Tuesday, July 25, 2017 5:25 PM
  • this command zip all files together.  it didnot zip seperatley like i mentioned above

    for /r c:\Backups %%f in (*) do (
    echo compressing files
    "C:\Program Files\7-Zip\7z.exe" a backup_cbk.7z 
    )

    Tuesday, July 25, 2017 6:48 PM
  • this command zip all files together.  it didnot zip seperatley like i mentioned above

    for /r c:\Backups %%f in (*) do (
    echo compressing files
    "C:\Program Files\7-Zip\7z.exe" a backup_cbk.7z 
    )

    A batch file to rename all .LOG files to .TXT in the 'demo' folder and all sub-folders:
    CD C:\demo\
    For /R %%G in (*.LOG) do Echo REN "%%G" "%~nG.TXT"

    CD C:\Backups

    For /R %%GG in (*.txt) do "C:\Program Files\7-Zip\7z.exe" a "%~nG_Backup.7z" 

    Your's isn't working Because A adds all the files to the static repository one by one. e.g. manage the name of the compressed file you are making to reflect the file you are backing up.

    Tuesday, July 25, 2017 7:20 PM
  • This is also doing the same thing it take all file and put all in together 

    for /R %%G in (*.txt) do (
    echo compressing files
    "C:\Program Files\7-Zip\7z.exe" a "%~nGbackup.7z"
    )

    Tuesday, July 25, 2017 7:35 PM
  • then continue to troubleshoot.
    Tuesday, July 25, 2017 7:44 PM
  • If you are not a trained technician, programmer or engineer you should not be using or trying to learn batch.  PowerShell is the replacement for batch.  Batch is obsolete and I am sure it will be removed from windows in the next major release.  Don't waste your time.  Spend it learning PowerShell.


    \_(ツ)_/

    Tuesday, July 25, 2017 7:56 PM
  • you are absolutely right i am a fresh graduated in COMPUTER ENGINEERING. and i dont like programming, i am interested in networking thats why doing some normal scripting for backing up files.

    if you have a good forum for POWERSHELL please let me know so i can start learning power shell

    Tuesday, July 25, 2017 8:05 PM
  • Windows PowerShell

    Every computer engineer must know basic programming. It is a requirement for graduation from any school I have ever known. Without an understanding of software how can you engineer anything about a computer.

    All  future network management will be done with PowerShell or other scripting systems like PowerShell. 

    I posted a simple piece of PS code above.  It should be very easy to understand for a degreed engineer.


    \_(ツ)_/

    Tuesday, July 25, 2017 8:11 PM
  • You grossly over estimate the education standards of this generation.  
    Tuesday, July 25, 2017 8:16 PM
  • i didnt say that i dont know programming. i did internship in web development and have my own sites.

    but my focus is on networking because i like it and i know some basic powershell 

    i want to learn more thats why asking for a good forum (y)

    Tuesday, July 25, 2017 8:23 PM
  • You grossly over estimate the education standards of this generation.  

    No.  A computer engineering degree requires two semesters of software studies.  Computers are useless without software.  I will agree that some two year schools and junior colleges don't do a very good job of teaching anything.


    \_(ツ)_/

    Tuesday, July 25, 2017 8:23 PM
  • i didnt say that i dont know programming. i did internship in web development and have my own sites.

    but my focus is on networking because i like it and i know some basic powershell 

    i want to learn more thats why asking for a good forum (y)

    If you know programming then you know that batch is not programming and nothing more than a mess Microsoft let IBM stick them with.

    If you know programming then PowerShell will be much easier than batch.


    \_(ツ)_/

    Tuesday, July 25, 2017 8:26 PM
  • i didnt use PowerShell yet thats why dont know the difference but i heard its a lot to learn about power shell.

    i know programming like i can manage the scripting etc. but forum is for helping when you are stuck on some points :)

    Tuesday, July 25, 2017 8:29 PM