Scripting - Need help with file path syntax

Monday, October 15, 2007 by DaveRI | Discussion: DesktopX

Hi:

The OMNI Slideshow widget uses a file "OMNIslideshow.ini" to save it's settings. The script line is:

FilePath=desktopx.ExecutableDirectory&"OMNIslideshow.ini"

I'd like to redirect that file from the "ExecutableDirectory" to user directories, either using a User variable or hardcoding the user into the script and using a seperate widget for each user. I've created seperate widgets and ini files for each user, but they're all still in the programs directory and I haven't been able to get the path re-defined.

From what little I've read on scripting, it seems that making use of a "user variable" would be more complicated than I want, but can someone tell me the syntax for hardcoding it to a different directory, for example "C:\Documents\User1\OMNI"? The standard windows convention didn't work for me, unless of course I botched it.

Thanks.
milksama
Reply #1 Monday, October 15, 2007 1:55 PM

You may want to have a look at this:
http://msdn2.microsoft.com/en-us/library/9x9e7edx.aspx

and this:
http://msdn2.microsoft.com/en-us/library/1c87day3.aspx

In short, I wouldn't recommend hard-coding anything -- you never know if a particular system's root drive might not be C:\, for example this machine I'm on now is on drive E:.

I would probably approach this by

  1. Use the information from the first link to establish the special folder in which you'd like to save the file
  2. Use the Properties from the second link to determine whether a particular folder already exists, if not, to create it
  3. Save the file

2 and 3 are probably already done in the script, I would assume, so doing the rest should be easy.

If you of course have any questions, feel free to ask.

-Mike
[Stardock Support]

SirSmiley
Reply #2 Monday, October 15, 2007 2:34 PM
That's funny I looked in the Windows Script Help file under GetSpecialFolder Method which doesn't reference the WshSpecialFolder Object at all.
milksama
Reply #3 Monday, October 15, 2007 3:42 PM

The GetSpecialFolder method belongs to the FileSystemObject, but seems like it's limited, feature-wise.

Sure would be nice if they did include that in the "See Also" section. I agree that it would seem a little appropriate.

-Mike
[Stardock Support]

DaveRI
Reply #4 Tuesday, October 16, 2007 10:52 AM
Thanks for the links, they do look like what I'd like to do. I looked at them, hacked around for quite awhile, couldn't get it to work. No big surprise there, I couldn't program my way out of a wet paper bag.

So I hard coded it. That worked fine this time around, don't know what my problem was before (see "wet paper bag" reference above  ). Agreed not the best solution, but it gets the job done, and duplicating that little widget a half dozen times still takes up less space that a single fat wallpaper.

I've bookmarked the links and I'll keeping poking around in there, maybe eventually I'll get half a clue. Thanks again.
milksama
Reply #5 Tuesday, October 16, 2007 11:16 AM

Glad to hear you got it working   

Here's a simple example of something you can use if you're interested:

Code: vbscript
  1. Const cFOLDER = "OMNI"
  2. Dim objFSO,objWSH,strMyDocs
  3.  
  4. Set objFSO = CreateObject("Scripting.FileSystemObject")
  5. Set objWSH = CreateObject("WScript.Shell")
  6. 'Use the Windows Scripting Host method to locate My Documents folder, concatenate your subfolder onto that 
  7. strSavePath = objWSH.SpecialFolders("MyDocuments") & "\" & cFOLDER
  8.  
  9. 'Does the Folder exist?
  10. If objFSO.FolderExists(strSavePath) = False Then
  11.   'No, create it
  12.   objFSO.CreateFolder(strSavePath)   
  13. End If
  14. 'Save your file code here. . .
  15. 'Cleanup
  16. Set objFSO = Nothing
  17. Set objWSH = Nothing

-Mike
[Stardock Support]

Please login to comment and/or vote for this skin.

Welcome Guest! Please take the time to register with us.
There are many great features available to you once you register, including:

  • Richer content, access to many features that are disabled for guests like commenting on the forums and downloading skins.
  • Access to a great community, with a massive database of many, many areas of interest.
  • Access to contests & subscription offers like exclusive emails.
  • It's simple, and FREE!



web-wc01