I have a list of folder addresses, which I then loop through with a foreach
. The routes look like this
C:\XXX\XXX\XXX\XXX\XXX\10-21-2020
C:\XXX\XXX\XXX\XXX\XXX\10-20-2020
At a certain moment I get the current date, when going through the foreach
name that is at the end of the route, for example , it "10-21-2020"
corresponds to October 10, 2020, which must be equal to the current date.
if (Path.GetDirectoryName(item) == fecha_actual)
{
}
I've tried to get this name, but I still can't, I keep sending the entire route and I just need"10-21-2020"
Path.GetDirectoryName
returns a full path when passed one.when you pass this string:
what that function does is search until the last \ and returns everything until there
if
10-21-2020
it's also a folder, that function doesn't know and thinks it's a file...but, taking advantage of that, if that is a folder, you can use the function
GetFileName
, which will return exactly that...You can do something like this, do a split and then get the last position and this way it works for you with any route: