Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check if folder(s) exist - if not make them

Status
Not open for further replies.

shabbarankers

Technical User
Jan 7, 2011
19
GB
Hi guys,

Im trying to create folders and copy files to a users appdata folder but Im not getting very far. Can someone please put me out of my misery - here is where I have got to

Code:
Dim objFSO, objWsh, appDataPath, pathToCopyTo, plainTextFile, plainTextFilePath, htmlFile, htmlFilePath
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWsh = CreateObject("WScript.Shell")
appDataPath = objWsh.ExpandEnvironmentStrings("%APPDATA%")
pathToCopyTo = appDataPath & "\Microsoft\Signatures\"
If Not (objFSO.FolderExists(pathToCopyTo)) then
objWsh.Run "cmd /c mkdir %appdata%\Microsoft\Signatures\"
CreateObject("Scripting.FileSystemObject").CopyFile "\\calsbs2008\signature$\SevernSTLogo.jpg", pathToCopyTo
End if

Thanks :)
 
You can't edit a post. Just re-post below with your corrections.

Jeff
[small][purple]It's never too early to begin preparing for [/purple]International Talk Like a Pirate Day
"The software I buy sucks, The software I write sucks. It's time to give up and have a beer..." - Me[/small]
 
Try this.
Code:
Option Explicit

Dim objFSO, objWSH, AppDataPath

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWSH = CreateObject("WScript.Shell")

AppDataPath = objWSH.ExpandEnvironmentStrings("%APPDATA%")

If objFSO.FolderExists(appDataPath & "\Microsoft") Then
	If objFSO.FolderExists(AppDataPath & "\Microsoft\Signatures") Then
		CopySignature(AppDataPath & "\Microsoft\Signatures")
	Else
		objFSO.CreateFolder(AppDataPath & "\Microsoft\Signatures")
		CopySignature(AppDataPath & "\Microsoft\Signatures")
	End If	
Else
	objFSO.CreateFolder(AppDataPath & "\Microsoft")
	objFSO.CreateFolder(AppDataPath & "\Microsoft\Signatures")
	CopySignature(AppDataPath & "\Microsoft\Signatures")
End If

Sub CopySignature(PathToCopyTo)
	objFSO.CopyFile "\\calsbs2008\signature$\SevernSTLogo.jpg",PathToCopyTo
End Sub
 
Correction. Please update line 3 to the following.
Code:
Dim objFSO, objWSH, AppDataPath, CopySignature, PathToCopyTo
I just realized that not all variables are declared on my initial post.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top