Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Reading the content of a FTP directory
Message
De
15/02/2012 13:15:16
 
 
À
15/02/2012 12:33:26
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01535473
Message ID:
01535486
Vues:
45
This message has been marked as a message which has helped to the initial question of the thread.
>>Instead of parsing it based on position, couldn't you use string.split (http://msdn.microsoft.com/en-us/library/ms131450.aspx) to extract the elements you need?
>
>Not really, FTP servers will sometimes only put the Month Day Hour when this is in the same year and Month Day Year when this is another year. Also, Unix and Windows format differs. So, I have to lookup at the string level and parse against the conditions that I need to support.
>
>But, thanks for the suggestion

In that case, maybe Regex can be of help - use named Groups

Example

After the day, I capture either a time or a year
		static void Main(string[] args)
		{
			string[] lines =
			{	@"-rw-rw-rw-   1 user     group        1402 Dec 30  2005 AmazonCA.gif",
				@"-rwxrwxrwx   1 owner    group            4480 Feb 15  2:25 8A17T2T1.txt"
			};

			string pattern = @"^(?<Permissions>\S+)\s+(?<Links>\d+)\s+(?<User>\w+)\s+(?<Group>\w+)\s+(?<FileSize>\d+)\s+(?<Month>\w+)\s+(?<Day>\d+)\s+((?<Year>\d{4})|(?<Time>\d+:\d+(:\d+)?))\s+(?<FileName>\S+)$";



			foreach (string line in lines)
			{
				Match m = Regex.Match(line, pattern);

				if (m.Success)
				{
					Console.WriteLine("Month {0}", m.Groups["Month"]);
					Console.WriteLine("Day {0}", m.Groups["Day"]);
					Console.WriteLine("Year {0}", m.Groups["Year"]);
					Console.WriteLine("Time {0}", m.Groups["Time"]);
					Console.WriteLine("FileName {0}", m.Groups["FileName"]);
				}
				else
					Console.WriteLine("No match");

			}


			Console.ReadLine();
			return;
				

		}
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform