cancel
Showing results for 
Search instead for 
Did you mean: 

Saving Picture to File with Spaces in File Name

Highlighted
Contributor

Saving Picture to File with Spaces in File Name

I am having trouble saving a screenshot with spaces in the file name (in strIDAndType below, taken from a property of an on-screen object in Chrome).



strFileName = "C:\CoverityIssues\" & strIDAndType & ".png"

Sys
.Desktop.Picture.SaveToFile(strFileName)



I have tried creating the file name like this but it does not help:



strFileName = """C:\CoverityIssues\" & strIDAndType & ".png"""



Any ideas?  





  




 


4 REPLIES 4
Highlighted
Community Hero

RE: Saving Picture to File with Spaces in File Name

Hi Magnus,



Just a quick check:

Might it be that strIDAndType variable contains characters that are not allowed in the file names?



Sys.Desktop.Picture.SaveToFile("c:\a a.png")

worked fine for me.
Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
Highlighted
Regular Contributor

RE: Saving Picture to File with Spaces in File Name

Try this out (i believe your problem happens because you're using only one slash)



Path = "C:\\folder\\subfolder\\auto tests\\";



Another useful function I found out is this:



 // function that executes path that contains space chars

var objShell = new ActiveXObject("shell.application");        

objShell.ShellExecute(ficheiro, "", "Path", "open", 1);
LinkedIn 😄 "A SQL query walks into a bar and sees two tables. Walks up to them and says 'Can I join you?'"
Highlighted
Contributor

RE: Saving Picture to File with Spaces in File Name

Not sure what caused this but I have never had to use \\ in paths that I can remember. I ended up creating the screenshot file name from strings taken from different on-screen objects instead.

Thanks anyway!
Highlighted
New Contributor

RE: Saving Picture to File with Spaces in File Name

When the image that gets imported has spaces in the file name they get imported and saved as HTML encoded characters. So a file that is: "imported file.png" will be saved as "imported%20file.png".



This will generally be ok on linux systems but in windows systems (IIS at least, not sure about apache), later use of the image will not work properly.



It should be saved as it originally was and maybe even have an option to allow the admin to replace spaces with dashes or something.



God help those who help themselves.
New Here?
Join us and watch the welcome video:
Announcements
Script Wanted
Let's start July with new challenges!

Create a script to pass custom command-line arguments as a test parameter for the TechCorner tag!

Will you dare to take the challenge?


Top Kudoed Authors