File mask

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

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


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.

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).

For file globbing you can use the following function. Credits go to to Erwin at http://www.codeproject.com/KB/string/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;

	}

}

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