assassinator
16th January 2006, 11:58
Now, I want to check a directory whether exists in my local harddisk, path likes "C:\COG_LCM Report". How can I get it? :confused:
RobertB
16th January 2006, 12:29
Here's a function I've used in the past:
|******************************************************************************
function domain tcbool local.file.name.ok()
{
domain tcbool file.ok, path.ok
long ext.pos, path.pos, f.len, ii, ret.val
string f.path(50), f.drive(1), f.char(1)
| Ref: "C:\TEMP\some_dir\myfile.txt".........
f.len = len(client.file)
file.ok = FALSE
if (shiftl$(strip$(client.file)) <> "") then
| Check that the filename has an extension...
ext.pos = pos(client.file, ".")
if (ext.pos > 0) then
| Replace any forward-slashes with backward slashes......
if (pos(client.file, "/") > 0) then
for ii = 1 to f.len
f.char = client.file(ii; 1)
if (f.char = "/") then
client.file(ii; 1) = "\"
endif
endfor
endif
| Get the path............
f.path = ""
path.pos = rpos(client.file, "\")
if (path.pos > 0) then
f.path = client.file(1; (path.pos - 1))
| Check whether the path is on C or D drive.....
f.drive = toupper$(f.path(1; 1))
if ((f.drive = "C") or (f.drive = "D")) then
| Check if directory exists - attempt to create it.....
|--------------- Reference - from baanboard.com -------------
|function create.local.directory(...)
|FunctionUsage
|Expl.: - This function creates a directory on the client
|Post: - The directory "client.dir" is created on the client
|Input: - client.dir -> the name and path of the directory
|Return: - 0 | succeed
| 183 | directory already exists
| <> 0 | failure
| 70 Permission is denied.
| 380 Invalid property value.
| 382 Property is read-only at run time.
| 383 Property is read-only.
| 394 Property is write-only.
|EndFunctionUsage
|----------------------- End Reference ----------------------
ret.val = create.local.directory(f.path)
path.ok = TRUE
if (ret.val = 0) then
|message("Directory created OK!")
else
|message("Directory already exists!")
endif
| If file does not exist, it will be created automatically.....
file.ok = TRUE
else
message("Drive must be local!")
endif
else
message("Please give the file a valid path!")
endif | path.pos > 0...
else
message("Please give the file a valid extension (e.g. " & chr$(34) & ".txt" & chr$(34) & ")!")
endif
else
message("Please enter a file-name!")
endif
return(file.ok)
}
HTH.
george7a
16th January 2006, 12:49
Now, I want to check a directory whether exists in my local harddisk, path likes "C:\COG_LCM Report". How can I get it? :confused:
You can also use create.local.directory (http://www.baanboard.com/programmers_manual_baanerp_help_functions_client_file_access_create_local_directory). It will create the directory if it doesn't exist. If it does, nothing will happen.
- George