How to get a file name as a variable?

file
code

#1

Hi everyone,

I have a folder named “C:\Desktop\Folder” and inside it, one file: “File.csv”.
Does anyone know how to get the whole “C:\Desktop\Folder\File.csv” as a variable?

Thanks!
Kazuo


#2

Hi Kazuo,

First thing to do is create a variable with any name with variable type DataTable. Then you create a Read CSV activity and input the file path. Then you go over to the Properties in the panel to the right and go to the Output and type in your variable name next to where it says DataTable.

Hope that helps!


#3

Hi @Kazuo

There is prebuilt activitie to read csv file and store its data into a Datatable. So you have to mention a variable which data type should be datatable so you can store that return activity output in that Datatable Variable.
After getting data into a Datatable you can perform required actions on data very easily by using its supported functions and efficiently too.

Things should be in mind

  1. If you are using csv field which are stored on different locations so you have to give absolute path of that CSV file.
  2. If you are running that workflow(Which is using that csv file)within a specific folder then you just have to pass that file name.
  3. Better approach is always use a structured folder approach so whateve input and output files you are using or generating use a particular folder where your workflows are already and where you wjll run them. So absolute path problems errors won’t genarte and u can run universally just by using that workflow folder approach.

Thanks &Regards…!!5


#4

Hi @nsl1006 , @aksh1yadav,

Thanks for your answers!

I’m sorry I wasn’t clear, but I can’t use an absolut path because that .csv file is always changing names. To be more precise, the .csv file inside the folder is an output to another application, so each time it runs it deletes the previous file and writes a new one with a new name.

Aksh1yadav,

Can you explain a bit more about the structured folder approach? It seems that’s what I need.

Cheers,
Kazuo


#5

hey @Kazuo

That is just a way to organize to mantain your workflows and dependent files it may be input and output should be at one place.

For example
If you have a SampleProject1 Folder project then there will be many dependent workflows will be there. Many of dealing with Only for input data purpose and many for only Process that data and many workflows for only to generate particualr output.
so what you can do inside that project folder just maintain Folders like Input(Will contains input related workflows),Output(Will contain output related workflows) and others can be at root.

My question to you is if you are taking a dynamic generated files that what name pattern it will generate? or where it will generate then one at a time? or ?

Regards…!!


#6

Hi,

If I’m not missing something, the question is how to find an absolute path to the file that is in a known folder, but the name is not known?
(not saying advice given here is incorrect, just that it may not answer the original issue)

If that’s so, please see the attached example below.
It boils down to Directory.GetFiles(folderPath) call that returns an array of strings with absolute paths to all files in that folder (non-recursive, ignores directories).
If you need directories only, use Directory.GetDirectories(folderPath).
If you need all use Directory.GetFileSystemEntries(folderPath)

FileTests.xaml (10.4 KB)


#7

Hi @andrzej.kniola

That is why i asked for if there will be more generated or single files in that folder then can use above mentioned .Net function because i have used that in my previous projects.

Thanks…!!


#8

Hi @aksh1yadav, @andrzej.kniola,

Thanks to both of you for the help.
The Directory.GetFiles(folderPath) is exactly what I was looking for. Due to this new learning, I think I will be able to complete a small Project I was working on, so you can imagine how happy and satisfied I am!

Best regards and have a good night!
Kazuo