Jump to content


Photo

File mask


  • Please log in to reply
5 replies to this topic

#1 Richard_B

Richard_B
  • Members
  • 24 posts

Posted 24 September 2010 - 06:35 PM

In the first version of the libary I had I do do a file mask on the file listing.

Now I have upgraded I no longer see the overloaded function GetFiles()

So now how do I apply a mask such as zbc*.t* to a directory listing?

Thanks

#2 mb

mb

    Developer

  • Administrators
  • 11528 posts
  • Gender:
    Male
  • Location:
    Worldwide

Posted 24 September 2010 - 06:36 PM

You need to filter the files yourself. What programming language do you use?

#3 Richard_B

Richard_B
  • Members
  • 24 posts

Posted 24 September 2010 - 07:33 PM

You need to filter the files yourself. What programming language do you use?


I use C#. What happened to the functionality that was in the libary before? I now have legacy code that will not upgrade without modifications.

#4 mb

mb

    Developer

  • Administrators
  • 11528 posts
  • Gender:
    Male
  • Location:
    Worldwide

Posted 25 September 2010 - 06:37 AM

Maybe you mean the ReadDirectoryFromCommand method.

If your server supports globbing you can use the function as following"
ReadDirectoryFromCommand("LIST zbc*.t*")
But the safer way is to manually enumerate the directory (see below).

#5 mb

mb

    Developer

  • Administrators
  • 11528 posts
  • Gender:
    Male
  • Location:
    Worldwide

Posted 25 September 2010 - 06:49 AM

For file globbing you can use the following function. Credits go to to Erwin at http://www.codeproje...ng/wildcmp.aspx


public static class StringExtensions
{
	public static bool WildcardMatch(this string str, string compare, bool ignoreCase)
	{
		if (ignoreCase)
			return str.ToLower().WildcardMatch(compare.ToLower());
		else
			return str.WildcardMatch(compare);
	}

	public static bool WildcardMatch(this string str, string compare)
	{
		if (string.IsNullOrEmpty(compare))
			return str.Length == 0;
		int pS = 0;
		int pW = 0;
		int lS = str.Length;
		int lW = compare.Length;
		while (pS < lS && pW < lW && compare[pW] != '*')
		{
			char wild = compare[pW];
			if (wild != '?' && wild != str[pS])
				return false;
			pW++;
			pS++;
		}
		int pSm = 0;
		int pWm = 0;
		while (pS < lS && pW < lW)
		{
			char wild = compare[pW];
			if (wild == '*')
			{
				pW++;
				if (pW == lW)
					return true;
				pWm = pW;
				pSm = pS + 1;
			}
			else if (wild == '?' || wild == str[pS])
			{
				pW++;
				pS++;
			}
			else
			{
				pW = pWm;
				pS = pSm;
				pSm++;
			}
		}
		while (pW < lW && compare[pW] == '*')
			pW++;
		return pW == lW && pS == lS;
	}
}


#6 Richard_B

Richard_B
  • Members
  • 24 posts

Posted 25 September 2010 - 09:31 PM

This will work for me, Thanks a lot.

In the first version there was a overloaded function called GetFiles(). You could pass in a wildcard as a parameter and it would only get the matches.

Richard




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users