Hello Team,
We have csv files named in this Format
Aus_Seller_out_20231120.csv
1)How do we generate the weekno and rename this file
Weekno based on date present in current csv filename
1)Aus_Seller_out_20231120.csv
: i.e 20231120(YYYYMMDD)
So accordingly weekno should be calculated Example if in this case we get 47 from YYYYMMDD
Then File name should be renamed as
2)Aus_Seller_out_wk4723_20231120.csv
We are updating file name by adding week no and the year in this case
The file name could be any year format
Aus_Seller_out_20201128.csv
Then according same operations are to be performed
Your suggestions are welcomed
Thanks team in advance
@NISHITHA
inputstr=outputstr.Split("_"c).Last.split("."c).first
math.Round(datetime.ParseExact(inputstr,"yyyyMMdd",system.Globalization.CultureInfo.InvariantCulture).DayOfYear/7)
newfile name=outputstr.Replace(inputstr,"Wk"+weekcount+"_"+inputstr)
can you try this once
1 Like
Thanks @Shiva_Nikhil for the prompt response will definitely try it
1 Like
Hello @NISHITHA
Kindly refer to this Xaml file you may get some idea
Forum_ChangeDateToWeeknumber.zip (48.8 KB)
Yoichi
(Yoichi)
5
Hi,
How about the following?
yourString ="Aus_Seller_out_20231120.csv"
varDate = DateTime.ParseExact(System.Text.RegularExpressions.Regex.Match(System.IO.Path.GetFileNameWithoutExtension(yourString),"\d+$").Value,"yyyyMMdd",System.Globalization.CultureInfo.InvariantCulture)
cal = System.Globalization.CultureInfo.InvariantCulture.Calendar
strWKNumber = cal.GetWeekOfYear(varDate, System.Globalization.CalendarWeekRule.FirstDay, System.DayOfWeek.Sunday).ToString("00")+varDate.ToString("yy")
yourString = System.Text.RegularExpressions.Regex.Replace(yourString,"(?=_\d+\.[^.]+$)","_"+strWKNumber)
Sample
Sequence.xaml (7.7 KB)
Regards,
Just one question @Shiva_Nikhil , @Gokul_Jayakumar and @Yoichi what if the file is present as
Aus_Seller_out_2020128.csv
i.e YYYYMMD instead of YYYYMMDD
Then how will it get handled
@NISHITHA
Use Multiple possible Format here as an array to get the date.
datetime.ParseExact(GetDate_Str,{"yyyyMMdd","yyyyMMd"},System.Globalization.CultureInfo.InvariantCulture,DateTimeStyles.None)
regex Expression
System.Text.RegularExpressions.Regex.Match(FileName,"\d{7,8}").ToString
Yoichi
(Yoichi)
9
Hi,
Can you try to modify expression as the following? “yyyyMMdd” to “yyyyMMd”
DateTime.ParseExact(System.Text.RegularExpressions.Regex.Match(System.IO.Path.GetFileNameWithoutExtension(yourString),"\d+$").Value,"yyyyMMd",System.Globalization.CultureInfo.InvariantCulture)
BTW as 2020128 can be identified 2020-12-8 or 2020-1-28, it’s not very good.
Regards,
Thanks @Gokul_Jayakumar and @Yoichi the approaches suggested are working 
1 Like
@NISHITHA
you can mention how many formats you want as shown below
math.Round(datetime.ParseExact(inputstr,{"yyyyMMd","yyyyMMdd"},system.Globalization.CultureInfo.InvariantCulture).DayOfYear/7)
system
(system)
Closed
12
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.