The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.

Guys, how do I mass-zip files?...

OrganichuOrganichu poopspeesRegistered User regular
edited May 2008 in Help / Advice Forum
I have an mp3, and an accompanying karaoke file, so about 14,000 different files, 7,000 mp3s, 7,000 karaoke files. I want to essentially zip each of the two corresponding file types together. I want to finish with 7,000 zip files. Is there a way I can zip these together into 7,000 different zip archives or rar archives without, you know, doing it 7,000 times?

Organichu on

Posts

  • AldoAldo Hippo Hooray Registered User regular
    edited May 2008
    Unless the karaoke+mp3 file are in the same map I think you're shit out of luck.

    Aldo on
  • LewishamLewisham Registered User regular
    edited May 2008
    What platform are you using?

    This is relatively simple on a *nix machine.

    Lewisham on
  • GdiguyGdiguy San Diego, CARegistered User regular
    edited May 2008
    Lewisham wrote: »
    What platform are you using?

    This is relatively simple on a *nix machine.

    This is a good question to answer, since it would be easier on Unix (/Apple by extension), but I *think* cygwin comes with a zip utility that would make it possible the same way on a Windows machine

    *edit

    though of course it depends on what it's set up as - if they have the same name but different extensions it's a trivial 5 line script, if the files aren't connected to each other in some reasonable way it'll be a pain in the ass

    Gdiguy on
  • OrganichuOrganichu poops peesRegistered User regular
    edited May 2008
    Using a basic iteration of Windows (either XP or Vista). The file names are identical, excepting the file type endings, of course.

    Organichu on
  • khainkhain Registered User regular
    edited May 2008
    Winrar has a command line utility that you can use when creating scripts.

    khain on
  • OrganichuOrganichu poops peesRegistered User regular
    edited May 2008
    khain wrote: »
    Winrar has a command line utility that you can use when creating scripts.

    Would you know of a script that could accomplish those things I'm looking to do? I don't know the first thing about what to type in to execute what I'm aiming for.

    Organichu on
  • BarrakkethBarrakketh Registered User regular
    edited May 2008
    Organichu wrote: »
    Using a basic iteration of Windows (either XP or Vista). The file names are identical, excepting the file type endings, of course.

    Are they all in the same directory?

    Barrakketh on
    Rollers are red, chargers are blue....omae wa mou shindeiru
  • OrganichuOrganichu poops peesRegistered User regular
    edited May 2008
    Barrakketh wrote: »
    Organichu wrote: »
    Using a basic iteration of Windows (either XP or Vista). The file names are identical, excepting the file type endings, of course.

    Are they all in the same directory?

    It's a few hundred folders in one big folder.... each folder has maybe 15-20 tracks.

    Organichu on
  • ecco the dolphinecco the dolphin Registered User regular
    edited May 2008
    Okay. I've whipped this up pretty quickly, so it's quite ... well, ugly and non-elegant, but it should work.

    Here we go.

    1.) Download this command line zip utility
    2.) From that zip archive, you only need to extract the zip.exe file. Place the zip.exe file in the base folder where you store your mp3/karaoke files
    3.) Copy and paste the "code" below into a batch file into a file called "mkmp3zip.bat" in the base folder where you store your mp3/karaoke files (i.e. same place as the zip.exe file)
    @echo off
    
    rem If we have no arguments, then it is assumed that we recurse looking for mp3s
    rem If we have an argument, it is assumed that it is the directory we're to search in
    rem The reason we don't dir/s/b *.mp3 is because the zip utility then saves the sub-directory
    rem and I assume that the user will not want the directory prefix to be saved along with the
    rem mp3/karaoke file
    
    if "%~1" == "" goto startRecurse
    
    set zipExe=%CD%\zip.exe
    set curDir=%CD%
    
    cd "%~1"
    for /f "delims=" %%i in ('dir/b *.mp3') do call :savemp3 "%%i"
    
    cd "%curDir%"
    
    goto endBatch
    
    :savemp3
    
    set basename=%~1
    
    rem Ensure that we are passed an mp3 extension
    set extension=%basename:~-4%
    if not "%extension%" == ".mp3" goto badParam
    
    rem Truncate the ".mp3" extension
    set basename=%basename:~0,-4%
    
    if exist "%basename%.zip" del "%basename%.zip"
    
    rem Only for debugging
    rem echo %basename%
    
    "%zipExe%" -D "%basename%.zip" "%basename%.mp3" "%basename%.txt"
    
    goto endBatch
    
    :badParam
    
    echo Error: %~1 is not an mp3 file.
    
    goto endBatch
    
    :startRecurse
    
    call "%~0" "%CD%"
    for /f "delims=" %%i in ('dir/ad/s/b') do call "%~0" "%%i"
    
    echo Done
    pause
    
    :endBatch
    

    4.) See the line:
    "%zipExe%" -D "%basename%.zip" "%basename%.mp3" "%basename%.txt"
    
    You need to replace the .txt with whatever extension the karaoke files are - I have no idea, I'm afraid.
    Also, if you find the zip taking too long because it's trying to compress, add a -0 behind -D. For example, if the karaoke files have the extension .kar, and the zip is taking too long, change the line to:
    "%zipExe%" -D -0 "%basename%.zip" "%basename%.mp3" "%basename%.kar"
    

    If, for whatever reason, you want to delete all the generated zip files, then change the line to:
    rem "%zipExe%" -D -0 "%basename%.zip" "%basename%.mp3" "%basename%.kar"
    

    5.) Save the batch file, and run it. Should display "Done" and prompt for any key when complete.

    Should work. I've given it a brief run through on my system, but don't guarantee it.

    EDIT: Crud, I just assumed that the mp3 files are in the same folder as the karaoke files. This batch file only works if that's the case.

    If that's not the case, then you'll have to give us more information on how the files are stored/folder layout.

    ecco the dolphin on
    Penny Arcade Developers at PADev.net.
  • OrganichuOrganichu poops peesRegistered User regular
    edited May 2008
    Firstly, whether this works or not thanks so so so much for spending all the time making that for me. That's awesome of you, I didn't realize it would take so much work and I am obscenely appreciative.
    eecc wrote: »
    EDIT: Crud, I just assumed that the mp3 files are in the same folder as the karaoke files. This batch file only works if that's the case.

    If that's not the case, then you'll have to give us more information on how the files are stored/folder layout.

    Using specious folder names, I essentially have:

    KARAOKE (1 big folder containing...) > Karaoke tracks 1, Karaoke tracks 2, etc. etc to Karaoke tracks 500, or whatever... not sure exactly how many folders there are. Each of the 'karate tracks 1', 'karate tracks 2', etc. folders possess the actual files. There are no files in the master directory (KARAOKE), only the hundreds of smaller folders containing the actual content.

    Organichu on
  • ecco the dolphinecco the dolphin Registered User regular
    edited May 2008
    Sounds promising! So if you have something like:

    KARAOKE
    > Karaoke tracks 1
    > > Music file 01.mp3
    > > Music file 01.kar
    > Karaoke tracks 2
    > > Music file 02.mp3
    > > Music file 02.kar
    > Karaoke tracks 3
    > > Music file 03.mp3
    > > Music file 03.kar

    then the batch file should just work, and put a zip file with the same name as the mp3/kar file in the same folder that they're in.
    Organichu wrote: »
    Firstly, whether this works or not thanks so so so much for spending all the time making that for me. That's awesome of you, I didn't realize it would take so much work and I am obscenely appreciative.

    No worries! I always wanted to brush up on my batch file scripting anyway. Besides, I'm apparently building.. uh... social capital or something right now. =P

    ecco the dolphin on
    Penny Arcade Developers at PADev.net.
  • OrganichuOrganichu poops peesRegistered User regular
    edited May 2008
    eecc: it's actually more like...

    KARAOKE
    >Karaoke tracks 1
    >>Karaoke tracks 1.mp3
    >>Karaoke tracks 1.kar
    >>Karaoke tracks 2.mp3
    >>Karaoke tracks 2.kar
    >>Karaoke tracks 3.mp3
    >>Karaoke tracks 3.kar
    >Karaoke tracks 2
    >>Karaoke tracks 4.mp3
    >>Karaoke tracks 4.kar
    >>Karaoke tracks 5.mp3
    >>Karaoke tracks 5.kar
    >>Karaoke tracks 6.mp3
    >>Karaoke tracks 6.kar

    etc.

    Is that cool?

    Organichu on
  • ecco the dolphinecco the dolphin Registered User regular
    edited May 2008
    Should be fine!

    If you're worried, maybe you could copy a small subset (e.g. 5-10) of your files to a new folder (e.g. KARAOKE2) with the same folder setup and see if it works/gives you what you want.

    ecco the dolphin on
    Penny Arcade Developers at PADev.net.
  • OrganichuOrganichu poops peesRegistered User regular
    edited May 2008
    Firstly, you are pretty much the most glorious motherfucker in the history of mankind. It worked on my test batch, and it's running right now and is several hundred tracks in. If ever you need some 'favors' ( ;) ), you know where my PM box is. :D

    Now, another small favor if I may impose...







    At this rate, when I add new files (matching .mp3 and .kar files, that is) and execute the .bat again, it restarts the entire process. Are there any modifications that I could make to the code that would effectively only work on the new, un-already zipped tracks? This isn't a 'huge' deal, because I could just introduce new stuff to a separate folder, run the .bat, then move it into the original one... but this would certainly be cool if you could figure out a fix for this.


    (either way you are God).

    Organichu on
  • ecco the dolphinecco the dolphin Registered User regular
    edited May 2008
    Oh. Glad it worked. =)

    To do what you want, replace the line:
    if exist "%basename%.zip" del "%basename%.zip"
    
    with
    if exist "%basename%.zip" goto endBatch
    

    ecco the dolphin on
    Penny Arcade Developers at PADev.net.
  • OrganichuOrganichu poops peesRegistered User regular
    edited May 2008
    I hope services rendered are payable via open mouthed kisses.

    Mods, without a doubt, conclusively solved!

    Organichu on
Sign In or Register to comment.