Page 1 of 1

I'm stuck with a little .bat, can i get some help pls?

Posted: 05 Jan 2010 23:28
by Devcon
Hello,

I'm trying to do a simple bat to check a folder, then chek if that folder has empty subfolders and then delete them, and then compress each remaining subfolder into separate files inside the passed folder (%1)

Something like this:

Code: Select all

Before processing: MainFolder -- Subfolder1 -- 3 Files
                              -- Subfolder2 -- 0 Files
                              -- Subfolder3 -- 6 Files
                                           ...
                              -- A lot more of folders

After processing: MainFolder -- Subfolder1.7z
                             -- Subfolder3.7z
                                           ...


I have this at the moment:

@ECHO OFF
for /f "delims=" %%i in ('dir "%~f1" /ad /b /s ^| sort /R') do rd "%%i"2>nul
DIR %1 /s /B /AD>%1.tmp
FOR %%i IN (%1.tmp) DO 7za.exe a %%i *.*

But it's not working, i already have spended 4 hours trying to figure the correct way, can i get some help please?

Thanks a lot :)

Posted: 07 Jan 2010 09:01
by sweener
How about this?

Code: Select all

@ECHO OFF
FOR /F "tokens=*" %%a in ('dir /ad /b /s ^| SORT /R') do (
  FOR /F "tokens=1-2" %%f in ('dir "%%a"') do (
    IF "%%g"=="File(s)" IF %%f==0 rd "%%a"
))


Then do your 7-zip stuff from there... I'm not as learned about compression but maybe this DOS will help.

I does a dir against the subfolder and looks for 'X File(s) y bytes' in the 'DIR' command. Let me know if that works...