Weird file stuff going on

Blitz3D Forums/Blitz3D Beginners Area/Weird file stuff going on

_PJ_(Posted 2009) [#1]
I'm not surehow useful posting my code is, but essentially, it's a rough scrappy prog to reorganise my music files.
The program works by reading info from the MP3 tags which is correct, then copies them into the corresponding and correct folder, checking first in case folders exist.

However, it seems that the program fails every 512 files. It simply exits for no discernable reason (yes, Debug is on but I fear it may be a memory issue)

Also, it seems to have difficulty (i.e. does not) delete the files after the copies have been done. I've uncompressed and unarchived the attributes on all the files, and ensured they are not Read-Only.

Seeing as the path is complete and correct, I'm at a loss to understand why the DeleteFile wont work. I imagine, it may consider the file to be still in use perhaps after the MP3 reading?



; ----------------------------------------------------------------------------- 
Graphics 1024,768





Global MyTitle$
Global MyArtist$
Global MyAlbum$
















Function readTagv1(filename$)

	Album$=""
	Songname$=""
	Artist$=""
	
	file=OpenFile(filename$)
	file = ReadFile(filename$)
	
	If (Not(file))
		Return
	End If
	SeekFile(file,FileSize(filename)-128)

	For i=0 To 2
		txt$ = txt$ + Chr(ReadByte(file))
	Next
	
	If txt = "TAG"
		txt = ""
		For i=0 To 29
			songname$ = songname$ + Chr(ReadByte(file))
		Next
		MyTitle$=songname$
		For i=0 To 29
			Artist$ = Artist$ + Chr(ReadByte(file))
		Next
		MyArtist$=Artist$

		For i=0 To 29
			Album$ = Album$ + Chr(ReadByte(file))
		Next
		MyAlbum$=Album$
		If MyAlbum$="" Then MyAlbum$="Singles"
	EndIf
	CloseFile file
End Function





















DIR=ReadDir(CurrentDir$())
Fl$=NextFile$(DIR)
	While (Fl$<>"")
	
		MyTitle$=""
		MyArtist$=""
		MyAlbum$=""
					
		pth$=CurrentDir$()+Fl$
		If ((FileType(pth$)=1))
			If ((Upper$(Right$(pth$,3))="MP3"))
				Organise(Fl$)
			End If
		End If
		Fl$=NextFile$(DIR)
	Wend
End

Function Organise(Filename$)
	
	oldpath$=CurrentDir$()+Filename$
	readTagv1(oldpath$)
	
	If (MyArtist$="")
		Return
	End If
	If (MyTitle$="")
		Return
	End If
	If (MyAlbum$="")
		Return
	End If
	
	MyArtist$=Trim$(MyArtist$)
	MyTitle$=Trim$(MyTitle$)
	MyAlbum$=Trim$(MyAlbum$)

	If ((Upper$(Left$(MyAlbum$,6))="UKNOWN"))
		MyAlbum$="Singles"
	End If

	Newpath$="H:\Audio\"
	Initial$=Upper$(Left$(MyArtist$,1))
	
	Select Initial$
		Case "A"NewPath$=NewPath$+"A-F\"
		Case "B"NewPath$=NewPath$+"A-F\"
		Case "C"		NewPath$=NewPath$+"A-F\"
		Case "D"NewPath$=NewPath$+"A-F\"
		Case "E"NewPath$=NewPath$+"A-F\"
		Case "F"
					NewPath$=NewPath$+"A-F\"
				
		Case "G"					NewPath$=NewPath$+"G-L\"

		Case "H"					NewPath$=NewPath$+"G-L\"

		Case "I"							NewPath$=NewPath$+"G-L\"

		Case "J"					NewPath$=NewPath$+"G-L\"

		Case "K"					NewPath$=NewPath$+"G-L\"

		Case "L"
					NewPath$=NewPath$+"G-L\"

		Case "M"NewPath$=NewPath$+"M-Q\"
		Case "N"NewPath$=NewPath$+"M-Q\"
		Case "O"		NewPath$=NewPath$+"M-Q\"
		Case "P"
			NewPath$=NewPath$+"M-Q\"
		Case "Q"
					NewPath$=NewPath$+"M-Q\"
		Case "R"NewPath$=NewPath$+"R-V\"

		Case "S"NewPath$=NewPath$+"R-V\"

		Case "T"NewPath$=NewPath$+"R-V\"

		Case "U"		NewPath$=NewPath$+"R-V\"

		Case "V"
					NewPath$=NewPath$+"R-V\"
		Case "W"					NewPath$=NewPath$+"W-Z\"

		Case "X"					NewPath$=NewPath$+"W-Z\"

		Case "Y"						NewPath$=NewPath$+"W-Z\"

		Case "Z"
					NewPath$=NewPath$+"W-Z\"
		Default
					NewPath$=NewPath$+"0-9\"
					Initial$="-"
	End Select
	
	NewPath$=NewPath$+Initial$+"\"
	MyFolder$=NewPath$+MyArtist$
	
	If (FileType(MyFolder$)<>2)
		CreateDir MyFolder$
	End If
	
	NewPath$=MyFolder$+"\"
	MyFolder$=NewPath$+MyAlbum$
			
	If (FileType(MyFolder$)<>2)
		CreateDir MyFolder$
	End If
	
	NewPath$=MyFolder$+"\"
	MyFile$=NewPath$+Filename$	
	
	tl=OpenFile("H:\Audio\Unsorted\log.txt")
	SeekFile(tl,FileSize("H:\Audio\Unsorted\log.txt"))
	
	WriteLine tl,"Processing: "+oldpath$
			
	If (FileType(MyFile$)<>1)
		CopyFile oldpath$,MyFile$
			
		If (FileType(MyFile$)=1)

				Print"MOVED: "
				Print"       "+oldpath$
				Print"TO:    "
				Print MyFile$

				WriteLine tl,oldpath$+" Moved to "+MyFile$
		End If
		
		DeleteFile oldpath$
						
	Else
		
		WriteLine tl,Myfile$+" Already Exists"
		WriteLine tl,"-----------------------------------------"
		DeleteFile oldpath$
						
	End If
	
	CloseFile tl
	
End Function




GIB3D(Posted 2009) [#2]
Ok I noticed this, your trying to Delete the file then Close it which may give an error.


_PJ_(Posted 2009) [#3]
I don't get any errors at all, however, the file that is deleted (oldpath) is deleted AFTER any read/write/copy or close.

If you're refering to 'tl' that's just a little log file I made to keep a record of what was moved. It doesn't get deleted.


Matty(Posted 2009) [#4]
Function readTagv1(filename$)

	Album$=""
	Songname$=""
	Artist$=""
	
	file=OpenFile(filename$)
	file = ReadFile(filename$)  <-- Memory leak is here, you are effectively opening the file twice and overwriting the handle stored from the openfile statement.



_PJ_(Posted 2009) [#5]
Thanks Matty, well spotted ;)

I remember changing that to ReadFile, Seems I forgot to remove the OpenFile.

Still, even without it, the problem remains :S


_PJ_(Posted 2009) [#6]
Finally found it... The issue causing the 512 file limit was due to a flag set on a Blitzsys function I was using.. >.>