Create path with string name and save file inside

Hi. I try with many methods and can’t do it.
I need this:

I will get NAME of my client using a string
Next, need create a path with my client’s NAME
And next, save the page inside this path,

I have the code to get the name, and to save, but now i save all in same path, like this:

C:/Clients/Eduard_info.pdf
C:/Clients/Eduard_photos.pdf
C:/Clients/John_info.pdf
C:/Clients/John_photos.pdf

And i need save like this:

C:/Clients/Eduard/info.pdf
C:/Clients/Eduard/photos.pdf
C:/Clients/John/info.pdf
C:/Clients/John/photos.pdf

But i don’t can find a code to create a path.
And most dificult yet, a code to determine a path where the browser will save (all time the browse only save in next path used)


I need a solution to:

  1. Create a path using a string
  2. Code to choice where the next file will be saved

PS: This code is a loop, i don’t can use a global code. I need a code of i can change in each loop, with the string of current client’s NAME

Use Java’s File class. To make the directory using the client’s name:

String clientName = "Eduard";
File directory = new File("C:/Clients/" + clientName);
directory.mkdirs();

Can you elaborate more on this? Are you saying that, after you create the directory that you need, you want to tell the browser to download to that directory?

1 Like

@felipe.dks

How do you get the info.pdf file of Eduard? Are you doing some sort of web page scraping? Does your test case script opens a URL in browser, select a <a href="http:/xxx.xxx.xxx/xx/x/info.pdf>Eduard info</a> node, click the Anchor tag to open the PDF and … how do you download the file and save it?

Please share your target HTML and your test case script.

Now my script make 2 process.
first save the informations in excel, second, press CRTL + P and save as .PDF
The informations like “name” and anothers, is inside string, to i can use in anothers commands and send to excel too.

The code for create a directory is perfect. This code:

String clientName = "Eduard";
File directory = new File("C:/Clients/" + clientName);
directory.mkdirs();

But after i’m created the directory, i need save the page inside.
I save the page using Robot.

I press CRTL + P, and save the page as PDF

My question now is:

How i can tell the script to save the file in "C:/Clients/" + clientName and not in the last save path, what is the default in Windows??

Or have another way to save page as PDF what not the CTRL + P?

Hmmm I’ve never really messed with saving a page this way. It’s going to be quite difficult to save a file to your directory this way, because as you’ve said, the default will just be whatever the previous path was that Windows was using.

What is your ultimate goal? Are you just trying to take a screenshot of the page? If so, there are much easier ways to do this.

Hello @Brandon_Hein,
1.I have 25 branches in the list while looping am selecting all the branches one by one and downloading csv files for that i set a path into desired capabilities so all the downloaded file are storing into that particular path.
2.Now my requirement is i need to create a separate folder for branch wise and i have download the csv’s into that particular branch folder.

Could you please help me how it will possible.