DoesFileExist("C:\files\*12345*.*")
....will return False, even when...
DoesFileExist("C:\files\A12345B.wpd")
....returns True.
Is there a way to do wildcards here that I'm missing?
Anyone still reading this? :|
Same in v9. Since the use of the function is usually a precaution before
operating on a specific file, this seems sensible.
--
Good wishes!
Roy Lewis
C_Tech volunteer
(UK)
So what you need to do, is use FileFind in a loop to locate each file
that matches your wildcard pattern, and then pass each file name that is
found to whatever other command you want to call.
Of course, this makes little sense for commands like DoesFileExist, or
DoesDirectoryExist, because those commands are called to see if
something exists, and by definition, FileFind will only return the names
of files (or directories) that really exist, so calling DoesFileExist or
DoesDirectoryExist for each result from FileFind is redundant.
Specifically when calling these 2 commands, a single call to FileFind is
almost a direct replacement. Apparently you only care is at least one
file or one directory which matches the wildcard exists, and you don't
particularly care what their names are.
Since a call to FileFind will return the first matching file or
directory, then this means that if it returns anything, then at least
something exists.
So to see if a file exists as an alternative to DoesFileExist, you would
only have to call:
If (FileFind ("C:\files\*12345*.*") != "")
// There are some matching files
EndIf
An equivalent to DoesDirectoryExist is a bit more difficult. By
default, FileFind only returns matching files, not directories. To
search for directories, you must include the Directory! value to the
second parameter, like this:
FileFind ("*.*"; directory!)
But, as the help states, "In addition to files, directories are also
returned. This does not return directories only.". So the names that
are returned are either files or directories, and you must then use the
GetFileAttributes command on each name returned, to see if the return
value includes the Directory! flag, like this:
vFile = FileFind ("*.*"; Directory!)
If ((GetFileAttributes (vFile) & GetFileAttributes!.Directory!) != 0)
// It is a directory
Endif
But since the first name returned by FileFind may not be a directory,
then you will actually have to call FileFind continually until one of
the names it returns is a directory, like this:
FoundDir = false
f = FileFind ("*.*"; Directory!)
While (f != "")
If ((GetFileAttributes (vFile) & GetFileAttributes!.Directory!)
!= 0)
// It is a directory
FoundDir = true
break
Endif
f = FileFind()
EndWhile
If (FoundDir)
// Found a directory
Endif
--
-J Dan Broadhead-
perfectscript _@_ bigfoot.com
(remove " " and "_")
I'll give FileFind a shot. In this case, I have directories of files with
filenames that are inconsistent, except that they all contain an ID number,
as in my example of A12345B.wpd. I can't necessarily predict what "A" or "B"
will be, but it doesn't matter too much because in this case, any file with a
name containing "12345" will work for what I'm doing. So, all I need to do is
grab the first one found with that string, not necessarily any one file. (I
need only one file, but I'm not picky about which one, within certain
parameters.)
I figured out a way to make due without a DoesDirectoryExist equivalent
(changing the directory structures of these files' paths to something
mathematically predictable, which is something I should have done a long time
ago anyway).
Thanks again.
This will not work.
FileFind calls Windows to locate the matching files. But unless Win2000
and XP have changed (I have not personally tried this myself) from
Win95, Win98, Windows only supports a single * wildcard in the pattern,
and no leading, only trailing, wildcards are supported.
Byt try it anyway - just don't get your hopes up.
APPLICATION (A1; "WordPerfect"; Default; "US")
global vPath;vContext
vFileArray[]:=FilenameArray("C:\MyFiles\*.*"; 1)
Fornext(x; 1; vFileArray[0])
Messagebox(DD;"File "+x;vFileArray[x])
Endfor
//*********************************************************
// Purpose: Get an array of filenames
// To use: vFileArray[]:=FilenameArray(vPath; vContext)
// Parameters:
// vPath = the path and mask to the files you want to get
// vContext = a numeric value, such as 1, 2, or 3. Use
// a different context for each separate search
// Remarks: Filenames are returned in the order in which they
// are stored in the File Allocation Table.
// Copyright (c) 1998 J. Jeppson All Rights Reserved
//*********************************************************
FUNCTION FilenameArray(vPath; vContext)
vCount:=CountFiles(vPath; vContext)
Declare vFileArray[vCount]
vFileArray[1]:=FileFind(vPath; ; vContext)
Fornext(x; 2; vCount)
vFileArray[x]:=FileFind(""; ;vContext)
Endfor
Return(vFileArray[])
ENDFUNC
FUNCTION CountFiles(vPath; vContext)
vFilename:=FileFind(vPath; ;vContext)
vCount:=1
Repeat
vFilename:=FileFind(""; ;1)
vCount:=vCount+1
Until(vFilename="")
Return(vCount)
ENDFUNC
//************************************************************
Inline 3 of course you substitute your folder for the C:\myfiles and in line
5 whatever command it is you want to perform on the files substitutes the
Messagebox command. I must point out that all credit for this solution goes
to Julie Jeppson - I have merely adjusted it slightly to suit your case.
good luck
Colin Bradley
"Cory Engel" <cory~c-engel@wrd~state-or.us> skrev i en meddelelse
news:419d0dac_1@cnews...
The problem is in the FileFind(""; ; 1) command inside the CountFiles
function.
The last parameter is called the context id, and a 1 is being passed
here. The context id can be specified by the caller if multiple
wildcard searches are being performed at the same time (which is not the
case here).
The first time FileFind is called, the wildcard pattern and attributes
are passed, and a contect id is specified (it defaults to 0). On all
FileFind commands after that, the filename and attributes are left off,
and the same context id must be passed in order to continue the search
for that same context.
The first call to FileFind in CountFiles, passes a variable for the
context id, which the caller passes in. In your case, you are passing a
1 from the main code to FilenameArray, which then passes it to
CountFiles. But the second call to FileFind is passing a 1
specifically. This works because the main program is also passing a 1
for the context id.
But if your main code were to pass any other value, like a 0 or a 2,
then CountFiles would fail, because it would still be using a 1 for the
second call to FileFind.
-
-J Dan Broadhead-
perfectscript _@_ bigfoot.com
(remove " " and "_")
-