Menu

#17 "shorten" AutoHotKey script submission

New
nobody
command (6)
Medium
2008-08-02
2008-08-02
Anonymous
No

Originally created by: kijoshua...@gmail.com

/*
    This was from a while ago!  I made this script to cleanup folders after
unzipping many
    things at once.  I always hated how some would zip their folders while
others would zip
    their items.  I just ended up extracting to a folder every time and then
checking each
    folder to see if it was redundant or not.  Like
   
    finding
    ...\mystuff\mystuff\<files>
    and fixing it to be
    ...\mystuff\<files>
   
    All this does is spills any selected folder that contains precisely one
folder and no files.
   
   

*/

loop %0%
{
    folder := %A_Index%
   
    files := 0
    loop, %folder%\*.*
        files++
       
    folders := 0
    loop, %folder%\*.*, 2
    {
        folders++
        real_folder = %A_LoopFileFullPath%
        real_fname = %A_LoopFileName%
    }
   
    if (files = 0) and (folders = 1)
    {
        StringGetPos,break,folder,\,[r1]
        StringLeft,dest,folder,%break%
        StringGetPos,break,dest,\,[r1]
        StringRight,dest_fname,dest,%break%
        ;MsgBox, changing %real_folder% to %dest%\%real_fname%
        FileMoveDir, %real_folder%, %dest%\%real_fname%, 2
        if ErrorLevel
            MsgBox, error changing %real_folder% to %dest%\%real_fname%
        else if  dest_fname <> %real_fname%
            FileRemoveDir, %folder%
    }
    if (files = 0) and (folders = 0)
        FileRemoveDir, %folder%
}

QUIT:
return

Related

Commit: [r1]

Discussion

  • Anonymous

    Anonymous - 2008-08-02

    Originally posted by: tortoisesvn

    (No comment was entered for this change.)

    Labels: -Type-Defect command

     
  • Anonymous

    Anonymous - 2008-08-02

    Originally posted by: kijoshua...@gmail.com

    Compiled version (doesn't require AutoHotKey to run)