ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Post New Requests Here

IDEA: Program to create subfolders and move files for list of shows BY name.

<< < (2/6) > >>

famewolf:
Hmm so would this change make it pass the filename in from command line?  The documentation for AHK says the script can be compiled to be a standalone exe.   I only have one directory but other beyondtv users might have multiple ones...with the ability to pass in the directory name they can call the script multiple times via windows scheduler...hmm would I need to remove the single instance parm then?


--- ---#singleinstance

if 0 < 1  
{
    MsgBox Directory must be passed after the command.
    ExitApp
}

SPath := %1%

loop, %spath%\*.*,0,0
{
    RegExMatch(a_loopfilename, "P)^(.*)-\d\d\d\d",TmpVar)
    if TmpVar
    {
        NewFold:= substr(a_loopfilename,1,tmpvar-5)
        filecreatedir, %spath%\%newfold%
        filemove, %a_loopfilefullpath%, %spath%\%newfold%
        tmpvar:=0
    }
}

Target:
not sure about the command line part (though I'm pretty sure your posted code isn't correct)

how about this then


--- ---#singleinstance

ifnotexist, showme.txt
msgbox, input file not found - script will exit

Loop, read,ShowMe.txt
{
    stringsplit, MyPath, A_loopreadline,`,
    loop, %Mypath1%\*.*,0,0
    {
        RegExMatch(a_loopfilename, "P)^(.*)-\d\d\d\d",TmpVar)
        if TmpVar
        {
            NewFold:= substr(a_loopfilename,1,tmpvar-5)
            filecreatedir, %Mypath2%\%newfold%
            errorlevel:=0

            filemove, %a_loopfilefullpath%, %Mypath2%\%newfold%
            if errorlevel
                fileappend, %a_loopfilefullpath%, ErrorLog_%A_YYYY%%a_mm%%A_dd%

            errorlevel:=0
            tmpvar:=0
        }
    }
}

replaces the INI file with a text file (ie ShowMe.txt) listing the matching source and target folders in the format

source folder 1,target folder 1
source folder 2,target folder 2
source folder 3,target folder 3
source folder 4,target folder 4
source folder 5,target folder 5

Script will loop through the matching pairs - same process, but it will handle multiple directories from a single calling.  any missed files will be logged to a file called ErrorLog_YYYYMMDD (a plain text file)

note that the text file needs to be in the same folder as the script/exe, and as before, if it's not found it will exit



famewolf:
Thanks..your script will work fine for me...I'm going to continue to play with the command line part though if for nothing more than an exercise to learn about auto hot key scripting.   The command line code should be close as it came from http://www.autohotkey.com/docs/Scripts.htm  ...will look into it more.  There really isn't need for source/target since the new folders should always be created under the original dir...at least in my particular scenario.

Script Parameters: The string(s) you want to pass into the script, with each separated from the next by a space. Any parameter that contains spaces should be enclosed in quotation marks. A literal quotation mark may be passed in by preceding it with a backslash (\"). Consequently, any trailing slash in a quoted parameter (such as "C:\My Documents\") is treated as a literal quotation mark (that is, the script would receive the string C:\My Documents"). To remove such quotes, use StringReplace, 1, 1, ",, All

The script sees incoming parameters as the variables %1%, %2%, and so on. In addition, %0% contains the number of parameters passed (0 if none). The following example exits the script when too few parameters are passed to it:

if 0 < 3  ; The left side of a non-expression if-statement is always the name of a variable.
{
    MsgBox This script requires at least 3 incoming parameters but it only received %0%.
    ExitApp
}

If the number of parameters passed into a script varies (perhaps due to the user dragging and dropping a set of files onto a script), the following example can be used to extract them one by one:

Loop, %0%  ; For each parameter:
{
    param := %A_Index%  ; Fetch the contents of the variable whose name is contained in A_Index.
    MsgBox, 4,, Parameter number %A_Index% is %param%.  Continue?
    IfMsgBox, No
        break
}

If the parameters are file names, the following example can be used to convert them to their case-corrected long names (as stored in the file system), including complete/absolute path:

Loop %0%  ; For each parameter (or file dropped onto a script):
{
    GivenPath := %A_Index%  ; Fetch the contents of the variable whose name is contained in A_Index.
    Loop %GivenPath%, 1
        LongPath = %A_LoopFileLongPath%
    MsgBox The case-corrected long path name of file`n%GivenPath%`nis:`n%LongPath%
}

Known limitation: dragging files onto a .ahk script may fail to work properly if 8-dot-3 (short) names have been turned off in an NTFS file system. One work-around is to compile the script then drag the files onto the resulting EXE.


--- End quote ---

Target:
I have no experience with the command line options - I've never needed it so I've never had to learn (but I'll be looking into it now!)

the code you posted probably was close, it just didn't look quite right to me...

There really isn't need for source/target since the new folders should always be created under the original dir
--- End quote ---

that was my original assumption - but who knows what other people do (or why!)

famewolf:
I tried to use this program tonight and ran into a few problems..hoping these are minor....

Instead of creating a folder of the show name and copying all episodes to that folder it's creating a folder with BOTH the show name and the episode name...example "Mental - (Manic at the disco)" instead of the folder just being named Mental.  It also tried to move a file currently being written to which resulted in the file being in both the folder AND the root dir but what concerns me more is it moved some of the other files associated with that show.  For each video it also has other files in my example with the same show name and maybe a different extension...I'm not sure what the result will be of having these moved in the middle of a recording.  Can the program attempt to move the *.tp files and only then move the .tp.index etc if that move was successful?  If a move gets an error can it not exist in the folder as well as root dir?

Was all that clear as mud?  While some shows are like Airwolf-2009-06-11-0.tp  some are also like Mental-(Manic at the disco)-2009-06-11-0.tp

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version