Sign in to follow this  
Followers 0
dufran3

Enumerating Directories and their names into an array

4 posts in this topic

Ok, here is what I'm trying to do, and I will post what I have so far. I have a directory...C:\Movies. I want to enumerate the number of directories inside of that directory, and create a count. I then want to somehow put the names of all of those directories into an array. And be able to change the directory names base on content. Basically, I have a movie collection, and want to search IMDB for the production year, using the directory name, say for example C:\Movies\The Dark Knight, and then rename the directory to say, The Dark Knight (2009). Not sure if this is even possible, but this is what I have so far.

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode
$mainwindow = GUICreate("Movie Finder", 300, 200)
GLOBAL $inputctrl = GUICtrlCreateInput('Input Movie Directory to Scan',1,1)
$OkButton = GUICtrlCreateButton('GO',20,180)
GUICTRLSetonEvent($OkButton, '_GO')
$ExitButton = GUICtrlCreateButton('Exit',50,180)
GUICtrlSetOnEvent($ExitButton, '_Exit')
GUISetOnEvent($GUI_EVENT_CLOSE, 'exitier', $mainwindow)
GUISetState(@SW_SHOW)

While 1
  Sleep(1000)  ; Idle around
WEnd

Func _GO()
    GLOBAL $Directory = GUICtrlRead($inputctrl)
    _Scan($Directory)
EndFunc

Func _Scan($directory)
    $array1 = DirGetSize($directory,1)
    $arraysize = $array1[2]

    Dim $aMovies[$arraysize]
    Exit
EndFunc


Func _Exit()
    Exit
EndFunc

Func Exitier()
    Exit
EndFunc   ;==>Exitier

Share this post


Link to post
Share on other sites



dufran3,

I want to enumerate the number of directories inside of that directory, and create a count

Look at _FileListToArray in the Help file. If you set $iFlag to 2, you only list the folders. :)

be able to change the directory names base on content

Look at StringInStr to find which folder names contain the required text and then DirMove to change the name.

All clear? ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Those functions work. Was trying to get the _FileListtoArray function to create a 2 dimension array, so that I can store the year for each movie in $array[$][0], still trying to figure that one out. Also, do you have any idea of a good way to get the movie year into the script? Seems like there would be an easier way than opening a browser, navigating to IMDB and trying to search the text for a year....thanks for your help thus far!

This is what I have now: trying to figure out the best way to populate the $Year and $Type. I figure I will scan the subfolder, and if a .mkv is found, set to [blu-ray], if Video_TS is found, set to [DVD]. But still need to work on the logistics of that.

#include <GUIConstantsEx.au3>
#include <File.au3>
#include <Array.au3>

Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode
$mainwindow = GUICreate("Movie Finder", 300, 200)
GLOBAL $inputctrl = GUICtrlCreateInput('Input Movie Directory to Scan',1,1)
$OkButton = GUICtrlCreateButton('GO',20,180)
GUICTRLSetonEvent($OkButton, '_GO')
$ExitButton = GUICtrlCreateButton('Exit',50,180)
GUICtrlSetOnEvent($ExitButton, 'Exitier')
GUISetOnEvent($GUI_EVENT_CLOSE, 'exitier', $mainwindow)
GUISetState(@SW_SHOW)

While 1
  Sleep(1000)  ; Idle around
WEnd

Func _GO()
    GLOBAL $Directory = GUICtrlRead($inputctrl)
    _Scan($Directory)
EndFunc

Func _Scan($directory)
    $aMovies = _FileListToArray($directory,'*',2)
    _ArrayDisplay($aMovies,"$FileList")

    For $i = 1 to $aMovies[0]
        $Year = '2009'
        $Type = 'Blu-ray'
        MsgBox(0,'','Move From: ' & @CRLF & $Directory & '\' & $aMovies[$i] & @CRLF &' To: ' & @CRLF & $Directory & '\' & $aMovies[$i] & ' [' & $Year & ']' & ' ' & '[' & $Type & ']')
        ;DirMove($Directory & '\' & $aMovies[$i], $Directory & '\' $aMovies[$i] & '[' & $Year & ']' & ' ' & '[' & $Type & ']',1)
    Next

    Exit
EndFunc


Func Exitier()
    Exit
EndFunc   ;==>Exitier
Edited by dufran3

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Glad to see your NFO problem is solved. One of the problems loading the movie info from IMDB is that there is often more than resultant one movie title so IMDB shows a list of titles. I think you would be fetter served by populating the corresponding NFO with the correct link and read your results from that NFO. Here is a rough script that can give you some insight (maybe) on doing an IMDB search. Once again, this is rough so if you want find a more efficient way of doing this, you should.

REQUIRES Firefox and FF.au3(found on the forum)

#include <FF.au3>

Local $File, $Movie, $Phrases
$Phrases = '(?i)DVDRip|(?i)DVDscr|(?i)R5|(?i)english|(?i)720p|(?i)1080p|(?i)1080i|(?i)BluRay|(?i)PROPER|(?i)x264|(?i)HDTV|(?i)HDDVD|(?i)UNRATED|(?i)REPACK|(?i)LIMITED|(?i)DTS|(?i)xvid|(?i)divx|(?i)mkv|(?i)avi|(?i)mpg|(?i)mp4|\[.*\]|\(.*\)|\{.*\}'

;Next If...Endif opens File Open Dialouge if not compiled and no Parameters are sent
If $CmdLine[0] = 0 Then
    $File = FileOpenDialog("Select an AVI file", @ScriptDir, "AVI Files (*.avi)", 1)
    If @error Then Exit
Else
    $File = $CmdLine[1]
EndIf

$Movie = StringRegExpReplace($File, '^.+\\|\.avi$', '') ;returns the AVI file name minus the path and extension
$Movie = StringRegExpReplace($Movie, $Phrases, '')  ;Strips common phrases/brackets, parentheses, and braces (and text between)
$Movie = StringRegExpReplace($Movie, ' *$', '') ;removes trailing spaces
$Movie = StringRegExpReplace($Movie, ' ', '+')  ;replaces spaces between words with "+" for correct IMDB search
MsgBox(32, 'Result', 'Ready to search IMDB for: ' & $Movie) ;shows the phrase to be searched in IMDB
If Not $Movie Then Exit ;if $Movie is blank, exit
_FFConnect()    ;open Firefox session and connect
Do
    Sleep(10)
Until _FFIsConnected()  ;Idle around until Firefox connection established
_FFTabAdd('http://imdb.com/find?' & $Movie) ;Search IMDB for your phrase
_FFLoadWait()   ;Wait until IMDB search page has loaded
MsgBox(32, 'Finished', 'Page finished loading...check results') ;exit message
Exit
Edited by Varian

Share this post


Link to post
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
Sign in to follow this  
Followers 0