Jump to content

Create .nfo file based on a file name with subdirs


jslegers
 Share

Recommended Posts

Hello,

I have seen this topic :

http://www.autoitscript.com/forum/index.php?showtopic=110281&st=0&p=775935&hl=nfo&fromsearch=1&#entry775935

Is it possible to run this script on files in sub directories ?

Example structure :

[Dir] Movie1

Movie1.mkv

[Dir] Movie2

Movie2.mkv

[Dir] Movie3

Movie3.mkv

Result :

[Dir] Movie1

Movie1.mkv

Movie1.nfo

[Dir] Movie2

Movie2.mkv

Movie2.nfo

[Dir] Movie3

Movie3.mkv

Movie3.nfo

The .nfo files need to be filled with an url of IMDB I will copy and paste that.

And if there is already an .nfo file it needs to skip the directory before it clears the old .nfo file.

John

Edited by jslegers
Link to comment
Share on other sites

Is it possible to run this script on files in sub directories ?

Yes, it's possible.

But don't expect 'us' to script it for you. This is a general help forum, post a sample script you made and comments where you are stranded. Then we could try to fix your non-working code. And please don't post an exact copy of the code from the link. ;)

Edit:

Ow, and please read this: Example for reproduction

Edited by Triblade

My active project(s): A-maze-ing generator (generates a maze)

My archived project(s): Pong3 (Multi-pinger)

Link to comment
Share on other sites

This should get you there in rough form; I did not create the "_FileListToArray_Recursive" function, found it on the Forum

#include <Array.au3>

Local $MediaFolder = 'Path To Root of your Media Folder'
Local $Array = _FileListToArray_Recursive($MediaFolder, '*', 1, 2, True)
If Not IsArray($Array) Then Exit
For $i = $Array[0] To 1 Step -1
    If Not StringRegExp($Array[$i], '(?i)avi$|(?i)mpg$|(?i)mpe$|(?i)mpeg$|(?i)mkv$|(?i)wmv$', 0) Then   ;Add or remove extensionss to suit your needs
        _ArrayDelete($Array, $i)
    Else
        If FileExists(StringTrimRight($Array[$i], 4) & '.nfo') Then _ArrayDelete($Array, $i)    ;If file passes your media filter, then check to see if NFO exists..if it does, remove it from the array
    EndIf
Next

$Array[0] = UBound($Array) - 1
_ArrayDisplayEx($Array, 'Media Files without Corresponding NFO')

For $i = 1 To $Array[0]
    If Not FileExists(StringTrimRight($Array[$i], 4)) & '.nfo' Then
        Local $File = FileOpen(StringTrimRight($Array[$i], 4) & '.nfo', 2)
        FileClose($File)
    EndIf
Next
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Functions Start;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;===============================================================================
; $iRetItemType: 0 = Files and folders, 1 = Files only, 2 = Folders only
; $iRetPathType: 0 = Filename only, 1 = Path relative to $sPath, 2 = Full path/filename
Func _FileListToArray_Recursive($sPath, $sFilter = "*", $iRetItemType = 0, $iRetPathType = 0, $bRecursive = False)
    Local $sRet = "", $sRetPath = ""
    $sPath = StringRegExpReplace($sPath, "[\\/]+\z", "")
    If Not FileExists($sPath) Then Return SetError(1, 1, "")
    If StringRegExp($sFilter, "[\\/ :> <\|]|(?s)\A\s*\z") Then Return SetError(2, 2, "")
    $sPath &= "\|"
    $sOrigPathLen = StringLen($sPath) - 1
    While $sPath
        $sCurrPathLen = StringInStr($sPath, "|") - 1
        $sCurrPath = StringLeft($sPath, $sCurrPathLen)
        $Search = FileFindFirstFile($sCurrPath & $sFilter)
        If @error Then
            $sPath = StringTrimLeft($sPath, $sCurrPathLen + 1)
            ContinueLoop
        EndIf
        Switch $iRetPathType
            Case 1 ; relative path
                $sRetPath = StringTrimLeft($sCurrPath, $sOrigPathLen)
            Case 2 ; full path
                $sRetPath = $sCurrPath
        EndSwitch
        While 1
            $File = FileFindNextFile($Search)
            If @error Then ExitLoop
            If ($iRetItemType + @extended = 2) Then ContinueLoop
            $sRet &= $sRetPath & $File & "|"
        WEnd
        FileClose($Search)
        If $bRecursive Then
            $hSearch = FileFindFirstFile($sCurrPath & "*")
            While 1
                $File = FileFindNextFile($hSearch)
                If @error Then ExitLoop
                If @extended Then $sPath &= $sCurrPath & $File & "\|"
            WEnd
            FileClose($hSearch)
        EndIf
        $sPath = StringTrimLeft($sPath, $sCurrPathLen + 1)
    WEnd
    If Not $sRet Then Return SetError(4, 4, "")
    Return StringSplit(StringTrimRight($sRet, 1), "|")
EndFunc   ;==>_FileListToArray_Recursive

Edited by Varian
Link to comment
Share on other sites

This should get you there in rough form; I did not create the "_FileListToArray_Recursive" function, found it on the Forum

#include <Array.au3>

Local $MediaFolder = 'Path To Root of your Media Folder'
Local $Array = _FileListToArray_Recursive($MediaFolder, '*', 1, 2, True)
If Not IsArray($Array) Then Exit
For $i = $Array[0] To 1 Step -1
    If Not StringRegExp($Array[$i], '(?i)avi$|(?i)mpg$|(?i)mpe$|(?i)mpeg$|(?i)mkv$|(?i)wmv$', 0) Then   ;Add or remove extensionss to suit your needs
        _ArrayDelete($Array, $i)
    Else
        If FileExists(StringTrimRight($Array[$i], 4) & '.nfo') Then _ArrayDelete($Array, $i)    ;If file passes your media filter, then check to see if NFO exists..if it does, remove it from the array
    EndIf
Next

$Array[0] = UBound($Array) - 1
_ArrayDisplayEx($Array, 'Media Files without Corresponding NFO')

For $i = 1 To $Array[0]
    If Not FileExists(StringTrimRight($Array[$i], 4)) & '.nfo' Then
        Local $File = FileOpen(StringTrimRight($Array[$i], 3) & '.nfo', 2)
        FileClose($File)
    EndIf
Next
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Functions Start;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;===============================================================================
; $iRetItemType: 0 = Files and folders, 1 = Files only, 2 = Folders only
; $iRetPathType: 0 = Filename only, 1 = Path relative to $sPath, 2 = Full path/filename
Func _FileListToArray_Recursive($sPath, $sFilter = "*", $iRetItemType = 0, $iRetPathType = 0, $bRecursive = False)
    Local $sRet = "", $sRetPath = ""
    $sPath = StringRegExpReplace($sPath, "[\\/]+\z", "")
    If Not FileExists($sPath) Then Return SetError(1, 1, "")
    If StringRegExp($sFilter, "[\\/ :> <\|]|(?s)\A\s*\z") Then Return SetError(2, 2, "")
    $sPath &= "\|"
    $sOrigPathLen = StringLen($sPath) - 1
    While $sPath
        $sCurrPathLen = StringInStr($sPath, "|") - 1
        $sCurrPath = StringLeft($sPath, $sCurrPathLen)
        $Search = FileFindFirstFile($sCurrPath & $sFilter)
        If @error Then
            $sPath = StringTrimLeft($sPath, $sCurrPathLen + 1)
            ContinueLoop
        EndIf
        Switch $iRetPathType
            Case 1 ; relative path
                $sRetPath = StringTrimLeft($sCurrPath, $sOrigPathLen)
            Case 2 ; full path
                $sRetPath = $sCurrPath
        EndSwitch
        While 1
            $File = FileFindNextFile($Search)
            If @error Then ExitLoop
            If ($iRetItemType + @extended = 2) Then ContinueLoop
            $sRet &= $sRetPath & $File & "|"
        WEnd
        FileClose($Search)
        If $bRecursive Then
            $hSearch = FileFindFirstFile($sCurrPath & "*")
            While 1
                $File = FileFindNextFile($hSearch)
                If @error Then ExitLoop
                If @extended Then $sPath &= $sCurrPath & $File & "\|"
            WEnd
            FileClose($hSearch)
        EndIf
        $sPath = StringTrimLeft($sPath, $sCurrPathLen + 1)
    WEnd
    If Not $sRet Then Return SetError(4, 4, "")
    Return StringSplit(StringTrimRight($sRet, 1), "|")
EndFunc   ;==>_FileListToArray_Recursive

Thanks for the replies. I will try it.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...