-1

So i have a dir called c:\user\jdoe\desktop\Folder1\

Inside folder1 i have many folders with subfolder and files.

I have a 7-Zip batch that zips all the folders in place. So now i have subfolders and subfolders.zip inside folder1.

I need a batch that will detele all the non zipped folders but skip the zip files and the .bat file that lives in c:\user\jdoe\desktop\Folder1\

Any ideas?

If i can get a 7-zip batch that will zip fodlers (example subfolder1.zip subfolder2.zip) and then afterwards delete all non zipped folders that would be great.

Been all over the internet and after deleting half my data by testing my own scripts i have now decided to come here.

Mo Heyns
  • 1
  • 2
  • 3
    Well that is as clear as mud. I suspect part of the reason you have not succeeded yet is because you have not precisely determined what the desired behavior should be. You certainly haven't specified in your "question". If you have code that is not working, best to show the code, describe what is supposed to happen, vs your actual results. – dbenham Dec 05 '17 at 16:56
  • Why do you not use the 7-Zip switch `-sdel` to let 7-Zip delete the files and folders after compressing them successfully into a ZIP file? Open help of 7-Zip (double click on file 7zip.chm in program files folder of 7-Zip), open __Contents__ item __Command Line Version__ and read about __Syntax__, __Commands__ and __Switches__. – Mofi Dec 05 '17 at 20:14
  • Well i dont know how you can not understand that question. "I need a batch that will detele all the non zipped folders but skip the zip files and the .bat file that lives in c:\user\jdoe\desktop\Folder1\" For ref here is my zip code for /d %%i in ("*.*") do "c:\program files\7-zip\7z.exe" a -tzip "C:\Users\elmo\Desktop\New folder\%%i.zip" "%%i" – Mo Heyns Dec 06 '17 at 07:44
  • @MoHeyns put code in backticks `\`like this\`` to make it readable – phuclv Dec 06 '17 at 11:03

1 Answers1

0

So after a long collaboration with a friend we came up with this. Tested this and it is working 100%

REM create list of directories
SET cwd="C:\Users\user\Desktop\New folder"
SET date=date /T
CD %cwd%
DIR /AD /B >dirlist.txt

REM Zip contents of each directory
for /f "tokens=*" %%a in (dirlist.txt) do (
  "c:\program files\7-zip\7z.exe" a "%%a.zip" "%%a"

  del /s /q "%%a" 
  rmdir /s /q "%%a"

)

del dirlist.txt

pause
phuclv
  • 37,963
  • 15
  • 156
  • 475
Mo Heyns
  • 1
  • 2