1

I am using task scheduler to run a batch file every few days to compress files on a backup drive to squeeze more files onto it.

This is what I use

H:
compact /c /s /i /exe:lzx
exit

Is there a way to make this run and ignore .7z files for example? I might add .mp4 .mkv to the list to ignore since those files are usually compressed anyways.

thanks

  • Sorry for not reply sooner, thankyou for your solution, it works EPIC! its great. Tho I could use some help with something, the set source code, can I use a folder? such as H:\Blender – ToxsickcitY Jul 6 '18 at 6:11
  • I dont know if you want to get involved with experimenting with this method I use for compacting. but.. I notice a strange behavior with compact, it actually has option /f to force re-compacting the file, since I dont use that I expect it to ignore compacted files and it does, but it seems that it takes ages to continue onto the next file. An example would be compacting a 1GB file may take 3-4minutes, but when compact gets to the same file on 2nd run it may take 1-2 minutes reading the file. Is there anything we can tweak? – ToxsickcitY Jul 6 '18 at 6:15
  • I am asking because I am compacting a stored HyperV backup (25GB) compacting takes an hour... goes from 30GB to 5GB.. thats pretty good! haha but running my batch again when gets to that file it just sits there.. i imagine reading the entire contents. If nothing can be done with an advanced batch, than I might set task scheduler to work on that file less often and start making the batch work in folders instead of entire drives! – ToxsickcitY Jul 6 '18 at 6:17
0

You can use a For /R loop along with some conditional If logic to only compact the files if the file extension is NOT .7z using some simple FOR loop substitutions to get the file extension from each iterated file name value the loop processes, and by specifying the file names with the command.


Script

set Src=H:\
for /r "%Src%" %%a IN (*) DO IF /I NOT [%%~Xa]==[.7z] compact /c /s /i /exe:lzx "%%~a"
::::for /r "%Src%" %%a IN (*) DO IF /I NOT [%%~Xa]==[.7z] IF /I NOT [%%~Xa]==[.mp4] IF /I NOT [%%~Xa]==[.mkv] compact /c /s /i /exe:lzx "%%~a"
exit

Further Resources

  • FOR /R
  • IF
  • Batch Substitutions (FOR /?)

    In addition, substitution of FOR variable references has been enhanced. You can now use the following optional syntax:

    %~nI        - expands %I to a file name only
    
  • Compact

    Syntax
          COMPACT [/C | /U] [/S[:dir]] [/A] [ /I] [/F] [/Q] [filename [...]]
    
    Key
    
      filename  Specifies a pattern, file, or directory.
    
|improve this answer|||||
  • This is an awesome solution and works a treat its EPIC!, I have commented above.. on the other post, can you take a look? – ToxsickcitY Jul 6 '18 at 6:19
  • @ToxsickcitY - Give a syntax of compact /c /i /exe:lzx "%%~a" simply omitting the /s switch as I suppose it's not needed since specifying the file names fully and explicitly; no need to do for all files again recursively since the for /r will do the recursion operations. See if that makes it any better but try removing the /i too and run it and see what happens. – Pimp Juice IT Jul 6 '18 at 17:41
  • 1
    Thanks for replying pimp. I will investigate. And report my findings. – ToxsickcitY Jul 8 '18 at 4:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.