RegEx driving me nuts - help needed
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: RegEx driving me nuts - help needed

  1. #1
    Join Date
    Oct 2012
    Posts
    2

    Question RegEx driving me nuts - help needed

    Hi

    I am no expert in regular expressions - and have for hours tried several things in order to solve my problem without any luck....

    I need a Regular Expression, that will match all files in a specific folder - except those ending in ".pst" ... And it must only match in the specified folder, not if a non-pst file exists in another folder..

    MS Outlook default places PST files in c:/users/username/AppData/Local/Microsoft/Outlook/ - so the path must match ".*/Users/.*/AppData/Local/Microsoft/Outlook"

    The files in that folder could be named:
    Code:
    Test.pst
    user.name@domain.com.ost
    test.local.pst
    In this case, the two files with the PST extension should not be listed/matched - but the file ending in .ost should....

    Can anyone help me ?

    Regards
    /R

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,474

    Re: RegEx driving me nuts - help needed

    Why are you using a regex to do this? Why not create a file object for the directory you want to look for files in and then call the File objects listFiles() method passing in a FilenameFilter to only accept files not ending in .pst.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

  3. #3
    Join Date
    Oct 2012
    Posts
    2

    Re: RegEx driving me nuts - help needed

    The problem is, that it is to be used as an exclusion mask in a pc backup product... Unfortunately I can only specify folders to be backed up - but not specify file wildcard together with the folder name...

    The only way to exclude non-PST files from backup, is to create a RegEx filter, that matches all non-PST files in the specified folder...

  4. #4
    Join Date
    May 2006
    Location
    UK
    Posts
    4,474

    Re: RegEx driving me nuts - help needed

    Sorry but you haven't added any information that makes me change my mind on the easiest way to solve this. FilenameFilters are designed for filtering file names, you can even use a regex within a FilenameFilter object if you really need to but I doubt that is necessary in your case as you are just filtering on the ".pst" extension.

    I'm not clear if you only want files with a .pst extension or those without it but it's essentially the same logic with a negated return value in one of the cases.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center