on 2016 Jan 22 10:25 AM
Today I use xp_read_file to see if a file exists or not. But on somtimes it return null even if a file exist?
if xp_read_file('\\\\\\server10\\\\folder1\\\\test.log') is null then 0 else 1 endif;
I guess there's better way than do like this to check if a file exist or not?
Just for completeness I'd like to add a further solution (although certainly not an "easy one", so I would prefer the directory access server for v12):
You can also create an external (native) function that calls an OS-level function to check for an existing file, say for Windows to call the GetFileAttributes API.
Breck has explained in his (former?) blog how to call a different WinAPI function (GetOpenFileName()) here:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Are you saying that doesn't pass the "something simpler" test? 🙂
SELECT 1 FROM sp_list_directory( '\\\\\\\\server10\\\\folder1\\\\' ) where file_path = '\\\\\\\\server10\\\\folder1\\\\test.log'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have this example that I use to check my backup logs:
create server backup_tree class 'directory' using 'root=L:\\LOG';
create externlogin dba to backup_tree;
create existing table backup_files at 'backup_tree;;;.';
After that, to check a file, you can just run a simple select:
select file_name from backup_files;
Your directory will work like a table. You can select, update and delete files. It works for me.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
75 | |
10 | |
10 | |
10 | |
10 | |
9 | |
8 | |
7 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.