Hi everyone,
how can I convert this code into string ? Can I use String.Join() for it ?
folderlist = Directory.GetDirectories(path,SearchOption.AllDirectories).Where(function(s) Not s.contains(“pathofFolder1”,“pathofFolder2”))
thanks
Hi everyone,
how can I convert this code into string ? Can I use String.Join() for it ?
folderlist = Directory.GetDirectories(path,SearchOption.AllDirectories).Where(function(s) Not s.contains(“pathofFolder1”,“pathofFolder2”))
thanks
@B.D What exactly are you referring to?
@supermanPunch
sorry I should have been more specific
folderlist is an array of string. the error is “… can’t convert system.io.searchoption into string”
@B.D I guess we need to know whats the return type of Directory.GetDirectories()
@B.D I guess the type of folderlist should be array of strings or a string
you were almost done
but the thing is we missed out a argument to be mentioned
kindly mention the expression like this
folderlist = Directory.GetDirectories(path,“**.*”,SearchOption.AllDirectories).Where(function(s) Not s.contains(“pathofFolder1”) or Not s.contains(“pathofFolder2”))
Cheers @B.D
thank you! I will try your suggestion. I have one more problem…
I’m trying to get the filerpath of the newest file. I found this method:
filepath(string) = String.Join(“”,Directory.GetFiles(folder,“FileType/FIleNameSequence",SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).CreationTime).Take(1))
“folder” is the string variable with the folderpath. The guy who posted it said it worked for him. but it doesn’t work for me. Any Idea ? What does “” and Take(1) at the end even stand for ?
Fine
if we are searching for a excel file that was created atlast
then
str_filepath = Directory.GetFiles(“yourfolderpath”,“*.xlsx”).OrderByDescending(Function (a) New FileInfo(a).CreationTime).ToList(0)
this will give the file path of the excel that was created atlast
to get any file that was created atlast
str_filepath = Directory.GetFiles(“yourfolderpath”).OrderByDescending(Function (a) New FileInfo(a).CreationTime).ToList(0)
here ToList(0) will convert the IEnumerable collection of file path to list of file path in DESCENDING order and 0 represents the first element in the list thus gives us the first file path
hope this would helpyou
Cheers @B.D
Kindly let know for any queries or clarification
Cheers @B.D
thanks fo the help!
sorry for asking so many questions, I’m very new to Ui Path and this is my first project
I have one question regarding your code. How would you modify it so it only searches for files of in the folder of the current day ?
also I have a question about changing the name of the file and moving it to a collective folder. I created the following workflow. but it doesn’t work as I want it to.
assign: filepath = ^^your code above
assign: filename (as String) = Path.GetFileName(filepath.ToString).ToString
assign: filename = filename.Split(“_”.ToCharArray)(0).ToString <= this takes a part of the filename and combines its with “New_” in the following copy activity
copy: "“C:…\Documents\NewRunFolder\New_+filename+.xlsx” <= this doesn’t work filename isn’t recognized as variable. also it only saves one file not the rest. do I have to use a for each loop ?
thanks
PS: maybe I can send you the workflow
@Palaniyappan
Ok I just saw my mistake it should have been “C:…\Documents\NewRunFolder\New_+" filename +".xlsx”
not “C:…\Documents\NewRunFolder\New_+ filename +.xlsx”
But I still get only one file saved instead of multiple new files…
to save multiple new files we can use timestamp along the file name like this
“C:…\Documents\NewRunFolder\New_+“filename”+Now.ToString(“hh_mm_ss”)+".xlsx”
hope this would help you
Cheers @B.D
kindly let know for any queries or clarificationc
Cheers @B.D
Hi Palaniyappen,
sorry to bother you again. What do I have to change of your code so it searches for the newest files (not in regards to creation date but change date) of the current Day
thanks
no problem buddy
actually this expression will give us the latest file regardless of either created today or yesterday
Cheers @B.D
oh ok, and what do I have to change so it searches for change time not creation time which have been newly changed in the current day?
PS: I editted the text
I found what I looked for in another topic. Thanks for the quick reply and explanation though, you helped me a lot!
Fantastic
Cheers @B.D
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.