Of all the aspects of XOJO the one that causes me the most confusion is folderitem. I accept its a powerful tool but maybe I am too set in my was of passing ‘strings’ as folderitems in the windows world to fully get my head around it. I have written the below piece of code, and it works - but it just seems ugly. I pass the method a homepath (i.e. into which the years/month subdirectories are going to go), and it returns a string with the full pathname (to pass to shell driven scanning software) to store the scanned file. Purely by way of learning about folderitem is there a better cross platform way of recoding this? PS. Ignore the additional variables i’ll get rid of them in due course
[code] //method to make a directory based on the date this is being scanned
//first does year directory exist? No - create it
//does month directory exist? No - create it
//now you have a path, return this for the doucment to be saved into
dim destination, newfolder as FolderItem
dim home as FolderItem=SpecialFolder.Documents.child(“0-scanned”)
'dim d as new date //create todays date for comparison
Dim d As New Date(2012, 4, 15)
dim mm, yyyy as string
dim destinationpath as string
mm=format(d.Month,“00”)
yyyy=format(d.year,“0000”)
if right (homepath,1)<>"" then
homepath=homepath+""
end if
//check whole path first
destination=getfolderitem(homepath+yyyy+""+“mm”+"")
if destination<>nil and destination.exists and destination.directory then
newfolder=destination
else
//check the year first
destination=getfolderitem(homepath+yyyy+"")
destinationpath=destination.NativePath
if destination<>nil and destination.exists and destination.directory then
//folder for year exists
else
//need to create year folder
newfolder=home.child(yyyy)
newfolder.CreateAsFolder
end if
//check the month second as its a subdir of year
destination=getfolderitem(homepath+yyyy+"\"+mm+"\")
destinationpath=destination.NativePath
if destination<>nil and destination.exists and destination.directory then
//folder for month exists
else
//need to create month folder
newfolder=home.child(yyyy+"\"+mm+"\")
newfolder.CreateAsFolder
end if
newfolder=destination
end if
return newfolder.NativePath
[/code]