Hot Topic (More than 10 Replies) Creating File Directory Index (Read 1814 times)
Acebanner
Full Member
***
Offline



Posts: 123
Location: New York City
Joined: Jan 23rd, 2008
Creating File Directory Index
Sep 22nd, 2010 at 7:57pm
Print Post Print Post  
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.

Code
Select All
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!
  
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Creating File Directory Index
Reply #1 - Sep 22nd, 2010 at 8:11pm
Print Post Print Post  
You can just catch the output from dir /A:-D /B /S . Try it on a command line and see if it's what you want.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Acebanner
Full Member
***
Offline



Posts: 123
Location: New York City
Joined: Jan 23rd, 2008
Re: Creating File Directory Index
Reply #2 - Sep 23rd, 2010 at 4:06pm
Print Post Print Post  
Yes, that works! Added "> index.txt" to the end of that command line and it works. Thanks Erica!
  
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Creating File Directory Index
Reply #3 - Sep 23rd, 2010 at 4:34pm
Print Post Print Post  
Acebanner wrote on Sep 23rd, 2010 at 4:06pm:
Yes, that works! Added "> index.txt" to the end of that command line and it works. Thanks Erica!

I'm glad it works for you. If you don't want to mess with the text file, take a look at the @RedirectProcess command.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Acebanner
Full Member
***
Offline



Posts: 123
Location: New York City
Joined: Jan 23rd, 2008
Re: Creating File Directory Index
Reply #4 - Sep 24th, 2010 at 3:02pm
Print Post Print Post  
Hammer wrote on Sep 23rd, 2010 at 4:34pm:
Acebanner wrote on Sep 23rd, 2010 at 4:06pm:
Yes, that works! Added "> index.txt" to the end of that command line and it works. Thanks Erica!

I'm glad it works for you. If you don't want to mess with the text file, take a look at the @RedirectProcess command.


The following programming makes Sesame crash.

Code
Select All
var vResult as String

vResult = @RedirectProcess("DIR", "")

If vResult <> "" Then WriteLn("Success.")
 



I can then unlock the design file. I created a new application with that programming in it (maybe it's an error related to the Preview function?) but got the same error.
  
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Creating File Directory Index
Reply #5 - Sep 24th, 2010 at 4:51pm
Print Post Print Post  
We're not getting the crash. Which OS are you on?
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Acebanner
Full Member
***
Offline



Posts: 123
Location: New York City
Joined: Jan 23rd, 2008
Re: Creating File Directory Index
Reply #6 - Sep 24th, 2010 at 5:58pm
Print Post Print Post  
Hammer wrote on Sep 24th, 2010 at 4:51pm:
We're not getting the crash. Which OS are you on?

I'm using Windows XP SP2.

Edit: also using Sesame 2.5.2
  
Back to top
IP Logged
 
Acebanner
Full Member
***
Offline



Posts: 123
Location: New York City
Joined: Jan 23rd, 2008
Re: Creating File Directory Index
Reply #7 - Sep 24th, 2010 at 6:10pm
Print Post Print Post  
Windows throws up an error report, asking if I want to send it to MS. Here's the report:

Quote:
<?xml version="1.0" encoding="UTF-16"?>
<DATABASE>
<EXE NAME="sesame.exe" FILTER="GRABMI_FILTER_PRIVACY">
    <MATCHING_FILE NAME="sdesigner.exe" SIZE="8359936" CHECKSUM="0xB4C6BA17" MODULE_TYPE="WIN32" PE_CHECKSUM="0x0" LINKER_VERSION="0x0" LINK_DATE="06/01/2010 19:17:54" UPTO_LINK_DATE="06/01/2010 19:17:54" />
    <MATCHING_FILE NAME="sesame.exe" SIZE="7835648" CHECKSUM="0x7DA19DC" MODULE_TYPE="WIN32" PE_CHECKSUM="0x0" LINKER_VERSION="0x0" LINK_DATE="06/01/2010 19:17:54" UPTO_LINK_DATE="06/01/2010 19:17:54" />
</EXE>
<EXE NAME="kernel32.dll" FILTER="GRABMI_FILTER_THISFILEONLY">
    <MATCHING_FILE NAME="kernel32.dll" SIZE="989696" CHECKSUM="0x2D998938" BIN_FILE_VERSION="5.1.2600.5781" BIN_PRODUCT_VERSION="5.1.2600.5781" PRODUCT_VERSION="5.1.2600.5781" FILE_DESCRIPTION="Windows NT BASE API Client DLL" COMPANY_NAME="Microsoft Corporation" PRODUCT_NAME="Microsoft® Windows® Operating System" FILE_VERSION="5.1.2600.5781 (xpsp_sp3_gdr.090321-1317)" ORIGINAL_FILENAME="kernel32" INTERNAL_NAME="kernel32" LEGAL_COPYRIGHT="© Microsoft Corporation. All rights reserved." VERFILEDATEHI="0x0" VERFILEDATELO="0x0" VERFILEOS="0x40004" VERFILETYPE="0x2" MODULE_TYPE="WIN32" PE_CHECKSUM="0xFE572" LINKER_VERSION="0x50001" UPTO_BIN_FILE_VERSION="5.1.2600.5781" UPTO_BIN_PRODUCT_VERSION="5.1.2600.5781" LINK_DATE="03/21/2009 14:06:58" UPTO_LINK_DATE="03/21/2009 14:06:58" VER_LANGUAGE="English (United States) [0x409]" />
</EXE>
</DATABASE>


Not sure if that helps. Seems I'm on SP3, actually.
  
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Creating File Directory Index
Reply #8 - Sep 24th, 2010 at 6:27pm
Print Post Print Post  
Acebanner wrote on Sep 24th, 2010 at 6:10pm:
Seems I'm on SP3, actually.

Me too, and I'm not crashing. I'll see if Support can replicate this.

Maybe there is some piece of security software "protecting" standard output on your system. Is there any way that you can try this on a different computer?
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Acebanner
Full Member
***
Offline



Posts: 123
Location: New York City
Joined: Jan 23rd, 2008
Re: Creating File Directory Index
Reply #9 - Sep 24th, 2010 at 6:32pm
Print Post Print Post  
Hammer wrote on Sep 24th, 2010 at 6:27pm:
Maybe there is some piece of security software "protecting" standard output on your system. Is there any way that you can try this on a different computer?


I've disabled Symantec Client Firewall for 5 minutes and re-tried, same results. Trying on another computer next.
EDIT: I've moved the application files to the server and tried accessing from a different PC, same result, Sesame crash and file locked. When I tried on the server PC itself, something strange -- Sesame crashes, but the database file remains unlocked.
  
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2482
Joined: Aug 20th, 2003
Re: Creating File Directory Index
Reply #10 - Sep 24th, 2010 at 6:53pm
Print Post Print Post  
Hello Acebanner,

Can you send to support@lantica.com your DSR and DDT files so that I can replicate this here? I can't get it to happen with just sample files.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
Acebanner
Full Member
***
Offline



Posts: 123
Location: New York City
Joined: Jan 23rd, 2008
Re: Creating File Directory Index
Reply #11 - Sep 24th, 2010 at 7:08pm
Print Post Print Post  
Quote:
Hello Acebanner,

Can you send to support@lantica.com your DSR and DDT files so that I can replicate this here? I can't get it to happen with just sample files.

-Ray


Just sent it -- thanks for the help!
  
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Creating File Directory Index
Reply #12 - Sep 24th, 2010 at 8:01pm
Print Post Print Post  
Found the problem and found why it happens there and not here. The problem is in the amount of information that is being "piped" through the @RedirectProcess command. When I use it in a smaller directory (or on Linux) it is fine. When I used it in a larger directory, it crashed here as well. Simply a "buffer overrun" problem. It will be fixed in the next release.

In the meantime, you can probably use the other code you already wrote. You have to be "recursive". So, when the routine encounters a directory, it calls itself with the accumulated directory path. That way it can descend down into sub-directories, building paths as it goes. Or, for now, you could use @Shell and use the redirect operator on the command line to write to a file, and then read that file.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Creating File Directory Index
Reply #13 - Sep 27th, 2010 at 3:27pm
Print Post Print Post  
Sorry for the double post, but I took a swipe at writing a recursive function that writes a directory listing, with sub-directories to a writeln window. While there appears to a bug that needed fixed on Linux (and has been), the Windows version of this seems to work well:

Put the following subroutine in GLOBAL CODE:
Code
Select All
** PROGRAMMING SECTION: [ GLOBAL CODE ] [] **

subroutine DirectoryScan(DirectoryPath as string)
var n as int            
var cnt as int
var vRawString as string    
var current_str as string
var str as string

        if(DirectoryPath <> "")
        {
                vRawString = @ServerListDirectory(DirectoryPath)
                cnt = @CountStringArray(vRawString)
                for n = 1 to cnt
                        current_str = @AccessStringArray(vRawString, n)
                        writeln(DirectoryPath + "\" + current_str)
                        DirectoryScan(DirectoryPath + "\" + current_str)
                next
        }
        else
        {
                @MsgBox("You must specify a directory to scan.", "", "")
        }
end subroutine

 



Then in the event that needs the listing:
Code
Select All
// Use a directory name as an argument, if you do not want the current directory (i.e.: ".")
DirectoryScan(".")
 



Also, the @DirectoryExists function does not tell you whether a file path is a directory or not. It simply indicates if it exists. It will indicate if it is a directory, in the next release.
« Last Edit: Sep 27th, 2010 at 4:40pm by The Cow »  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged