Filtering the File Record
NaviDev
Member Posts: 365
Hello,
I am trying to retrieve the TXT files using the File record. In the directory I have this files :
Sales.txt
Purchase.txt
_Sales.txt
_Purchase.txt
But I want to exclude those TXT files with "_" in the begining of the filename. So I have put in my code this :
But somehow in the results, it still includes the files with "_" in the beginning of their filenames. ](*,)
Please hand me some suggestions. Thanks in advance.
I am trying to retrieve the TXT files using the File record. In the directory I have this files :
Sales.txt
Purchase.txt
_Sales.txt
_Purchase.txt
But I want to exclude those TXT files with "_" in the begining of the filename. So I have put in my code this :
rFile.RESET;
rFile.SETRANGE(Path, 'c:\');
rFile.SETRANGE("Is a File", TRUE);
rFile.SETFILTER(Name, '%1|%2', '*.txt', '<>_*.txt');
IF rFile.FIND('-') THEN REPEAT
MESSAGE(rFile.Name);
UNTIL rFile.NEXT = 0;
But somehow in the results, it still includes the files with "_" in the beginning of their filenames. ](*,)
Please hand me some suggestions. Thanks in advance.
Navision noob....
0
Comments
-
0
-
Thanks Belias for the response. Too bad, I am using non Sql db with Nav 5.0. Is there any I can do with this. ](*,)Navision noob....0
-
Hi,
Try this:rFile.SETFILTER(Name, '''*.txt''&<>''_*.txt''');
Regards,
ReijerReijer Molenaar
Object Manager0 -
Hello reijermolenaar,
I tried your inputs but still with the same results... Still includes the files with "_" in the begining of their filenames.Navision noob....0 -
Just try this:
rFile.RESET; rFile.SETRANGE(Path, 'c:\'); rFile.SETRANGE("Is a File", TRUE); rFile.SETFILTER(Name, '%1', '*.txt'); // <-- IF rFile.FIND('-') THEN REPEAT IF rFile.Name[1] <> '_' THEN // <-- MESSAGE(rFile.Name); UNTIL rFile.NEXT = 0;Timo Lässer
Microsoft Dynamics NAV Developer since 1997
MSDynamics.de - German Microsoft Dynamics Community - member of [clip]0 -
-
@reijermolenaar
I think you are using Sql db.
@Timo
Many Thanks for the suggestion. I know I can do it that way with the help of function COPYSTR. But the scenario is much more complicated actually. I have a setup wherein user can put what are the filenames to include and exclude in the output. So I cannot put my code that way.
My code is like this :ExcludeFile1 := '_*.txt'; ExcludeFile2 := '*_*.txt'; ExcludeFile3 := '*1234*.txt'; ExcludeFile4 := '*8765*.txt'; ExcludeFile5 := '*+_)('.txt'; ExludeFiles := '<>' + ExcludeFile1 + '|<>' + ExcludeFile2 + '|<>' + ExcludeFile3 + '|<>' + ExcludeFile4 + '|<>' + ExcludeFile5; rFile.RESET; rFile.SETRANGE(Path, 'c:\'); rFile.SETRANGE("Is a File", TRUE); rFile.SETFILTER(Name, '%1|%2', '*.txt', ExludeFiles); IF rFile.FIND('-') THEN REPEAT MESSAGE(rFile.Name); UNTIL rFile.NEXT = 0;
Any suggestion will be greatly appreciated. Thanks again in advance.Navision noob....0 -
Yep, you are right, I should have read you post better…
I thought that the problem was lying in the fact that you were using a `|`-sign instead of a `&`-sign.
But the problem is that the filter `<>_*` is not working with a native db.Reijer Molenaar
Object Manager0 -
@reijermolenaar
I have test your codes in SQL db and its working.... but too bad I am using Native db
.
Anyways... I am trying to do it also in sql. But my code now is like the codes In my last post. How can I apply your code in that codes? Thanks again in advance.Navision noob....0 -
NaviDev wrote:@reijermolenaar
I think you are using Sql db.
@Timo
Many Thanks for the suggestion. I know I can do it that way with the help of function COPYSTR. But the scenario is much more complicated actually. I have a setup wherein user can put what are the filenames to include and exclude in the output. So I cannot put my code that way.
My code is like this :ExcludeFile1 := '_*.txt'; ExcludeFile2 := '*_*.txt'; ExcludeFile3 := '*1234*.txt'; ExcludeFile4 := '*8765*.txt'; ExcludeFile5 := '*+_)('.txt'; ExludeFiles := '<>' + ExcludeFile1 + '|<>' + ExcludeFile2 + '|<>' + ExcludeFile3 + '|<>' + ExcludeFile4 + '|<>' + ExcludeFile5; rFile.RESET; rFile.SETRANGE(Path, 'c:\'); rFile.SETRANGE("Is a File", TRUE); rFile.SETFILTER(Name, '%1|%2', '*.txt', ExludeFiles); IF rFile.FIND('-') THEN REPEAT MESSAGE(rFile.Name); UNTIL rFile.NEXT = 0;
Any suggestion will be greatly appreciated. Thanks again in advance.
I cannot understand what this code should do...
Are you applying a filter like this?rFile.SETFILTER(Name, '%1|%2', '*.txt', '<>a.txt|<>b.txt');
(this is an example). In this case i expect to retrieve every file in the folder...the name of a file will ever be different from a.txt or from b.txt... :-k
if so, do you know that "|" is "OR"? and "&" is "AND"
or maybe i'm missing something... :-k :-k :-k :-k :-k0 -
Hmmm...
Yeah I think my bad coding and analysis also... :oops:
I didnt consider the operator..
Belias and reijermolenaar are right. Operator should be '&' not '|'.
Anyways what I want to do is to retrieve all the files '*.txt' in the directory but exclude those files that are in the variables ExcludeFile1 - 5 (from my code).Navision noob....0 -
You can do something like this:
IncludeFilter := '*.txt'; ExcludeFilter := '_*.txt'; rFile.SETRANGE(Path, 'c:\test\'); rFile.SETRANGE("Is a file", TRUE); rFile.SETFILTER(Name, IncludeFilter); rFile2.SETRANGE(Path, 'c:\test\'); rFile2.SETRANGE("Is a file", TRUE); rFile2.SETFILTER(Name, ExcludeFilter); IF rFile.FINDSET THEN REPEAT rFile2 := rFile; IF NOT rFile2.FIND('=') THEN MESSAGE(rFile.Name); UNTIL rFile.NEXT = 0;Reijer Molenaar
Object Manager0 -
Hello reijermolenaar,
Thanks for the inputs. I already manage to do it, as the way you did it.Navision noob....0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 611 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 253 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions

