Hi, I working for excel data manipulation project. I have to pick the latest date modified file from a folder and I have to copy paste the file in same folder and change the date of the file to 2 days prior to current date. The name of the file will be like “Nameofthefile as of 09/08/201” and should change the file name to “Nameofthefile as of 09/07/2021”. The date should be change as per current date.
I have used assign activity and able to get the latest modified file, Now I unable to understand how to change the file name and copy paste the same. Can anyone help??
Thanks.
That is 1 day right? You have mentioned 2 days from the current date right which 09/06…
Please provide your sample file name and the screenshot of what you have tried so far which didn’t work?
I am sorry for that the old excel file will be of dated 09/05/2021 and the new file date should be 09/06/2021
So file name date plus 1 day right??
“Please provide your sample file name”. Because file won’t be having / which is not allowed.
It is ‘-’
okay. Please read my post again…I have already asked twice to share the sample file name so that I can give you a proper code to split the date and add days to it.
The reason why I am asking is, date part can be anywhere in the filename.
I cant share the sample file here instead I am sharing the dummy file name which is having the same format and same no of letterGardeswild files mains abcdef as of 09-06-2021.xlsx (8.5 KB)
I did not asked for sample file…All I asked is just sample file name…not the FILE…
Okay, The filename which I have given, it will be helpful right?? the sample filename is “Gardeswild files mains abcdef as of 09-06-2021.xlsx”
Sequence.xaml (7.7 KB)
This the sequence i tried
yes that is helpful…I see 09-06 date on it…and you want to create another of the file with the date 09-05 right?
I want to copy the file with date 09-07, which is like next date of the original file date
@nagini.pragna - First you can use the below code add days plus 1 …you can club and do it in a single line…
Next, while copying to a new name you can use the below code in the “To” section and the date which was created above…
Hope this helps…Give it a try, if you get stuck I will show you how to do…
Yes Sure I will try. Thanks for the help
Were you able to solve it??
I was able to change the file name, i am stuck at copy and paste the file in same folder.
Thanks for the solution It worked.
This is how I did it…
StrFilePath = "Date\Gardeswild files mains abcdef as of 09-06-2021.xlsx"
From = "Date\Gardeswild files mains abcdef as of 09-06-2021.xlsx"
To = "Date\" + path.GetFileNameWithoutExtension(StrFilePath).split({"as of"},StringSplitOptions.RemoveEmptyEntries)(0) +"as of "+cdate(path.GetFileNameWithoutExtension(StrFilePath).split().Last).AddDays(1).ToString("MM-dd-yyyy") + ".xlsx"
path.GetFileNameWithoutExtension(StrFilePath).split({“as of”},StringSplitOptions.RemoveEmptyEntries)(0) → This will give me "Gardeswild files mains abcdef "
cdate(path.GetFileNameWithoutExtension(StrFilePath).split().Last).AddDays(1).ToString(“MM-dd-yyyy”) → This will give me “09-07-2021”
Final outptut
Hope this helps…
Thanks, i will try this
Hi, I am facing error “Copy File: Conversion from string "" to type ‘Date’ is not valid.”
my code is in copy file is
from: lastestModified
To: Str_FolderPath+""+path.GetFileNameWithoutExtension(StrFilePath).split({“as of”},StringSplitOptions.RemoveEmptyEntries)(0) +"as of "+cdate(path.GetFileNameWithoutExtension(StrFilePath).split().Last).AddDays(1).ToString(“MM-dd-yyyy”) + “.xlsx”
StrFilePath:path.GetFileNameWithoutExtension(lastestModified).split({“as of”},StringSplitOptions.RemoveEmptyEntries)(0).ToString
Str_FolderPath:E:\FolderName
LatestModified:String.Join(“”, Directory.GetFiles(Str_FolderPath,“.xlsx”,SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(1) )
can you please check.
The variables all are of string type.
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.