I've got a networked directory that contains all of my company's artwork files. We make custom graphics. What often happens is that a previous client will contact one of my sales reps and ask "Do you have my art from the last job I did with you?" The sales reps then ask my graphic artist to 'check the files' and see if we have the artwork. The files are usually placed in a subdirectory that follows a specific naming convention, the job number and then the name of the company or client.
My sales reps are good with clients -- not so good with computers! If I gave them direct access to the directory itself they would hardly have the capability of performing a comprehensive search, and would likely delete, move or disorder the files. So I'm trying to find some way of indexing everything within a certain directory.
But I'm having trouble with handling subdirectories and their contents. I'm toying around with a sample db using the @LocalListDirectory command, but it only gives me a straight down listing of just the one directory, it doesn't handle subdirectories. I wrote the following code to check the returned string array for subdirectories, and can get two strings -- one with just files, and another with only subdirectories.
var n as Int // Looping variable.
var vRawString as String // The first result.
var vSubDirs as String // When complete, will contain string arry of subdirectories.
var vFilesOnly as String // When complete, will contain only files.
IF DirectoryPath <> ""
{
IF @DirectoryExists(DirectoryPath) = 1
{
WriteLn("The directory: " + DirectoryPath + " exists!")
vRawString = @LocalListDirectory(DirectoryPath)
vRawString = @UniqueStringArray(vRawString)
WriteLn("There were " + @CountStringArray(vRawString) + "items found.")
FOR n = 1 to @CountStringArray(vRawString)
IF @DirectoryExists(DirectoryPath + "\" + @AccessStringArray(vRawString, n) + "\") = "yes"
{
vSubDirs = @AppendStringArray(vSubDirs, DirectoryPath + "\" + @AccessStringArray(vRawString, n) + "\")
}
ELSE // This is a file, not a sub-directory.
{
vFilesOnly = @AppendStringArray(vFilesOnly, @AccessStringArray(vRawString, n))
}
NEXT
WriteLn("vFilesOnly = " + vFilesOnly)
WriteLn("vSubDirs = " + vSubDirs)
DirectoryContents = vFilesOnly
}
ELSE Clear(DirectoryContents)
}
ELSE @MsgBox("You must specify a directory to scan.", "", "")
It works, but I'm unsure how to make Sesame continue to work its way downwards through the file structure so that when it's done I'll have a single string array containing just the file names in all the subdirectories. With that string I could then allow sales reps to check the string for company and client names, and it would give them some sense of whether we have the artwork. They would still have to rely on someone else to get the file, but they would at least have some way of knowing.
Is there some simpler way of doing this that I'm missing? I thought maybe a While loop could do it, but I've always steered clear of them!