RE: MI finding files in a windows directory whose name contain a specific string

1999-10-13 Thread Dave Langley

Hi Ben,
Below is a snippet of code that allows you to retrieve file names
located in a particular directory. The first argument of the FindFirstFile
API call can either be a string that specifies a valid directory or path and
filename, which can contain wildcard characters (* and ?). In my example
below I'm searching for all the Word documents (.doc) in the c:\temp
directory. Make sure you include all the constants, type and function
declarations in your MB code and also remember to release the
FindFirstFileHandle at the end!!

Hope this helps,

Dave.

Dave Langley

Mapping Applications Consultant
Dataview Solutions Ltd
London
UK

***

define MAX_PATH 260

Type FILETIME
dwLowDateTime As Integer
dwHighDateTime As Integer
End Type

Type WIN32_FIND_DATA
dwFileAttributes As Integer
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Integer
nFileSizeLow As Integer
dwReserved0 As Integer
dwReserved1 As Integer
cFileName As String * MAX_PATH ' This is the 'long' file name of the
file
cAlternate As String * 14 ' This name is in the classic 8.3
(filename.ext) filename format.
End Type

Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal
lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Integer
Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal
hFindFile As Integer, lpFindFileData As WIN32_FIND_DATA) As Integer
Declare Function FindClose Lib "kernel32" Alias "FindClose" (ByVal hFindFile
As Integer) As Integer

Dim FindFileData as WIN32_FIND_DATA
Dim FindFileHandle,FindCloseResult as Integer

FindFileHandle=FindFirstFile("c:\temp\*.doc",FindFileData)

do
  print FindFileData.cFileName
loop until (NOT FindNextFile(FindFileHandle,FindFileData))

FindCloseResult=FindClose(FindFileHandle) ' release the FindFileHandle

Dave Langley

Mapping Applications Consultant
Dataview Solutions Ltd
London
UK

Telephone:  +44 (0)1635 581355
Mobile:+44 (0)973 797769

Business email: [EMAIL PROTECTED]
Personal email: [EMAIL PROTECTED]

Dataview Home Page: www.dataview-solutions.co.uk
_
WARNING - THIS E-MAIL TRANSMISSION IS CONFIDENTIAL.
This e-mail transmission (including any accompanying attachments)
contains confidential information which is intended for the named
addressee only. If you are not the intended recipient, you are hereby
notified that any use, dissemination, distribution or reproduction of
this e-mail is prohibited. If you have received this e-mail in error please
contact us immediately at [EMAIL PROTECTED] Thank you.
_


--
To unsubscribe from this list, send e-mail to [EMAIL PROTECTED] and put
"unsubscribe MAPINFO-L" in the message body, or contact [EMAIL PROTECTED]



RE: MI finding files in a windows directory whose name contain a specific string

1999-10-13 Thread Warren Vick, Europa Technologies Ltd.

Hello Ben,

> I was wondering if it is at all possible to somehow query the windows
> environment about the files contained in a specific directory.  The idea I
> had was that I would query a directory where an open table resides for a
> file containing a certain string in its name.

Yes, it is possible, but yet again it involves venturing into the Windows
API. There are two functions which you need to use. The first allows you to
setup the file search filter and returns the first matching file. The second
allows you to fetch successive file names. The functions are both "legacy"
in nature and are therefore preceded by an underscore.

   long _findfirst(char* filespec, struct _finddata_t *fileinfo)
   long _findnext(long handle, struct _finddata_t *fileinfo)

I've never tried to access these before directly from MB and think there may
be a problem with reproducing the _filedata_t structure with correct byte
packing, etc. I've always wrapped the functions into my own DLL which is MB
accessible, and provides an easy way to return matching files using a simple
MB do loop.

Regards,
Warren Vick
Europa Technologies Ltd, U.K.
http://www.europa-tech.com

--
To unsubscribe from this list, send e-mail to [EMAIL PROTECTED] and put
"unsubscribe MAPINFO-L" in the message body, or contact [EMAIL PROTECTED]



RE: MI finding files in a windows directory whose name contain a specific string

1999-10-13 Thread Thomas Brix Lyng

Hi Ben

A solution could be:

In a MapBasic program use 

iTable=TableInfo(Denver, TAB_INFO_TABFILE) 

to get the tables directory.

use

Open File "C:\temp\mydoscom.bat" For Output as #1
and
Print #1 ""+Left$(iTable,3)
to change the drive

Print #1 "Dir *buffer* /s >c:\temp\Test.txt"
then
Close file #1

Use this to run the batch file:

Run Program "Shell32.exe C:\temp\mydoscom.bat"

Then use
Dim k, m as integer
Dim Lines(1) as string

k=0

Open file "c:\temp\Test.txt" For Input As #1

Do while not EOT(1)
k=k+1
Loop

Redim Lines(k)

m=1

Do while not EOT(1)
Lines(m)=Line Input #1
m=m+1
Loop
Close File #1

to read each line in the file to a variable.

Within each variable in Lines(#) search for ".TAB":

Dim i as integer

For i=1 to k
Dim A as String
Dim Tablename(i) as string

A=InStr(Lines(#),".tab"
If Not A=0 then '".TAB" is in the string
Tablename(i)=Mid$(stringvariable,40,A-1)
'column 40 is the starting column of the file name
if any
End if
  Next

'***

Tablename(i) should now contain each table with the string "buffer"
(or something else).


CBU  (Complex But Usable)


Regards 

Thomas Brix Lyng
Frederikshavn County Administration
Denmark
> --
> Fra:  Humphrey, Ben[SMTP:[EMAIL PROTECTED]]
> Sendt:12. oktober 1999 23:34
> Til:  '[EMAIL PROTECTED]'
> Emne: MI finding files in a windows directory whose name contain a
> specifi c string
> 
> Baby steps outside the mapinfo environment...
> 
> I was wondering if it is at all possible to somehow query the windows
> environment about the files contained in a specific directory.  The idea I
> had was that I would query a directory where an open table resides for a
> file containing a certain string in its name.
> 
> For example if I had denver.tab open from a certain directory I would want
> to search for any tables in that directory whose name contained the string
> "buffer"
> 
> Can it be done???
> 
> And since it has always been the case in the past, there will be a reward.
> This time, seeing that it is a more complex question, my first born child
> is
> up for grabs.
> 
> thanks,
> Ben
> --
> To unsubscribe from this list, send e-mail to [EMAIL PROTECTED] and put
> "unsubscribe MAPINFO-L" in the message body, or contact [EMAIL PROTECTED]
> 
--
To unsubscribe from this list, send e-mail to [EMAIL PROTECTED] and put
"unsubscribe MAPINFO-L" in the message body, or contact [EMAIL PROTECTED]