Sign in to follow this  
Followers 0
sonicxtacy02

making a playlist creator...something weird goin on in my filewrite loop

8 posts in this topic

#1 ·  Posted (edited)

I'm in the process of creating an advanced "New Release" playlist creator. Its purpose is to add new tracks to a playlist when they've been added to my music folder(added to the computer in the last 30 days). The way i see acheiving this is to gather a list of all my album folders and check the date created. If its within 30 days from the current date all the .mp3 files within those folders are added to a .m3u list. Eventually this script will also delete songs from the playlist that are older than 30 days... but for now.. babysteps!

Here's my current problem. The script in its current form writes the folder names multiple times and i cant figure out why. Here's my script

#Include <File.au3>
#Include <Array.au3>
global $stringtested
$FileList=_FileListToArray("C:\documents and settings\administrator\my documents\my music\")
If (Not IsArray($FileList)) and (@Error=1) Then
    MsgBox (0,"","No Files\Folders Found.")
    Exit
EndIf
;debug line
_ArrayDisplay($FileList,"$FileList")
_FileWriteFromArray("C:\filepath.txt",$filelist)
$i=1
while 1
    $string=filereadline("C:\filepath.txt",$i)
    if @error=-1 then ExitLoop
    $i=$i+1
    if not stringinstr($string,".") then $foldertested=$string
    filewriteline("C:\folderpath.txt",$foldertested)
    msgbox(0,"TEST",$foldertested)
WEnd

The folders in the music file are 46, TEST, and Playlists. This is my current folderpath.txt. filepath.txt is written as it should be. So what gives?

BTW if anyone has any ideas on how to get the folders ina more efficient way by all means share. I'm doing it this way simply because this is the only way i know how to :)

folderpath.txt

Edited by sonicxtacy02

Share this post


Link to post
Share on other sites



You could do something like

#include <Array.au3>
  
Global $RootDirs[1]

_Getdirs('C:\')
_ArrayDisplay($RootDirs, "Test")
    
Func _GetDirs($Path)
    $search = FileFindFirstFile($Path & "*.")
    while 1
        $file = FileFindNextFile($search)
        If @error Then ExitLoop
        _ArrayAdd($RootDirs, $File)
    WEnd    
EndFunc

easily adaptable to include sub dirs, depending on what your code calls for.

Share this post


Link to post
Share on other sites

You could do something like

#include <Array.au3>
  
Global $RootDirs[1]

_Getdirs('C:\')
_ArrayDisplay($RootDirs, "Test")
    
Func _GetDirs($Path)
    $search = FileFindFirstFile($Path & "*.")
    while 1
        $file = FileFindNextFile($search)
        If @error Then ExitLoop
        _ArrayAdd($RootDirs, $File)
    WEnd    
EndFunc

easily adaptable to include sub dirs, depending on what your code calls for.

that works but i'm unaware of how to make it include all subdirectories in a given folder

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

As I said, depending on your code and what else you want to do...

but for a general check you can do somthing like.

#include <Array.au3>
  
Dim $RootDirs[1]
Dim $SubDirs[1]
Dim $Dirs = 'C:\' 

;Usage: _GetDirs(RootPath, Array)

_GetDirs($Dirs, $RootDirs)
_ArrayDisplay($RootDirs, "Test")
;on my machine $RootDirs[6] = "mp3"
_GetDirs($Dirs & $RootDirs[6] & "\", $SubDirs)
_ArrayDisplay($SubDirs, "Test")

Func _GetDirs($Path, ByRef $a)
    $search = FileFindFirstFile($Path & "*.")
    while 1
        $file = FileFindNextFile($search)
        If @error Then ExitLoop
        _ArrayAdd($a, $File)
        $RootDirs[0] = $RootDirs[0] + 1
    WEnd    
EndFunc

Edit: By the way this is the same thing as doing dir *. at a command prompt. In which case you will get files that have no extentions into the array. You can do a check like DirSize on each element in the array to make sure it's a Dir. Or DllCall Kernel32 to GetFileAttributes I think.

Edited by Nezoic

Share this post


Link to post
Share on other sites

As I said, depending on your code and what else you want to do...

but for a general check you can do somthing like.

#include <Array.au3>
  
Dim $RootDirs[1]
Dim $SubDirs[1]
Dim $Dirs = 'C:\' 

;Usage: _GetDirs(RootPath, Array)

_GetDirs($Dirs, $RootDirs)
_ArrayDisplay($RootDirs, "Test")
;on my machine $RootDirs[6] = "mp3"
_GetDirs($Dirs & $RootDirs[6] & "\", $SubDirs)
_ArrayDisplay($SubDirs, "Test")

Func _GetDirs($Path, ByRef $a)
    $search = FileFindFirstFile($Path & "*.")
    while 1
        $file = FileFindNextFile($search)
        If @error Then ExitLoop
        _ArrayAdd($a, $File)
        $RootDirs[0] = $RootDirs[0] + 1
    WEnd    
EndFunc

Edit: By the way this is the same thing as doing dir *. at a command prompt. In which case you will get files that have no extentions into the array. You can do a check like DirSize on each element in the array to make sure it's a Dir. Or DllCall Kernel32 to GetFileAttributes I think.

Ok i've figured my way around that issue and can now successfully pull all the folders i need.

My next question is how do i check if a file is less than 30 days old? I wrote a function that appears to work but i guess i'm just looking for someone to gimme situations in which it wouldnt work (kinda hard to test considering i cant change the date created on files)

Func Get_date()
    $t=filegettime($FILES[$X],1)
    if not @error then
        $date= $t[2]
        $month= $t[1]
        if $month = @mon then 
            if $date <= @mday Then
                filewriteline("C:\new versions.m3u",$FILES[$x])
            Else
            EndIf
        Else
            if $month = (@mon-1) Then
                if $date >= @mday Then
                    filewriteline("C:\new versions.m3u",$FILES[$x])
                Else
                EndIf
            Else
            endif
        EndIf   
    EndIf
EndFunc

Share this post


Link to post
Share on other sites

Ok i've figured my way around that issue and can now successfully pull all the folders i need.

My next question is how do i check if a file is less than 30 days old? I wrote a function that appears to work but i guess i'm just looking for someone to gimme situations in which it wouldnt work (kinda hard to test considering i cant change the date created on files)

For a quick answer, base it off your system date/time. To test change your system date ahead, or back whatever the case maybe.

Also you may want to check this out for extended file properties.

extprop.au3

Share this post


Link to post
Share on other sites

For a quick answer, base it off your system date/time. To test change your system date ahead, or back whatever the case maybe.

Also you may want to check this out for extended file properties.

extprop.au3

Nezoic, first of all great job on getting the extended file properties for a file.

I was wondering if it was possible to set any of the extended file attributes?

Thanks in advance.

Share this post


Link to post
Share on other sites

Nezoic, first of all great job on getting the extended file properties for a file.

I was wondering if it was possible to set any of the extended file attributes?

Thanks in advance.

bump...anyone?

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