Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

The Claptain posted:

Hello Goons, I have two problems I'd appreciate some input on.

First: I am tracking some stuff related to weekly releases via Azure App Config feature flags. Feature flags are in a format of $environmentName-$releaseVersion, where releaseVersion is a string of format YYYY-WW, so for example this week's one would be 2023-14. I would like to delete the feature flags older than 5 releases.

That format is something that is easy to construct from get-date cmdlet, as the get-date -UFormat %V will give the week number, and (get-date).year will return the, uhh, year. But converting that string to something that can be compared to date-time object escapes me. Looking at the docs for DateTime struct, it is read-only, so I cannot just construct it at will. So how do I go by comparing two strings that represent YYYY-WW format? Comparing weeks is easy enough, but I have no idea how to handle year rollovers on subtraction/addition.

you say that you want to keep the last 5, not keep them based on some property of the dates themselves; and they are in YYYY-WW format. so why not just compare the strings? you don't need to turn them into dates to do what you describe. they will compare the correct way lexicographically

Adbot
ADBOT LOVES YOU

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Pile Of Garbage posted:

Genuinely interested, what environment are you in where that is a compatibility issue? Windows and POSIX has no issues with files and folders having the same name, what monstrosity are you using which doesn't?

??????

Only registered members can see post attachments!

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
Being mistaken happens to the best of us.

Yes I think I would agree and generalise what you're saying as: it is useful to keep in mind the need to be aware whether you're testing for existence of files, directories, or both. One reason is to want to know whether a filesystem object is created and is specifically a directory, so (ignoring security for the moment) you would expect to be able to create things inside it. I'm more likely to be writing C# than Powershell code, and using Directory.Exists() or File.Exists(). But there too I might want to check both, to avoid leaving the silly edge case where I test whether a directory existed, and it didn't, but the program will still blow up when I try to create the directory because a file existed with that name.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply