PC Review


Reply
Thread Tools Rate Thread

Create folder in vbscript

 
 
New Member
Join Date: Mar 2009
Posts: 1
 
      13th Mar 2009
a much easier way is shown in this function I just made, feel free to use it however you wish

if NOT makeFolder("c:\Program Files\xpto\123\client\") then wscript.echo "problem making folder"

'===============
'makeFolder it creates a folder and it's subfolders
'===============
function makeFolder(byVal pFolder)
makeFolder=FALSE
dim oShell
set oShell = WScript.CreateObject ("WSCript.shell")
oShell.run "cmd.exe /c md """ & pFolder & """"
makeFolder=TRUE
end function
 
Reply With Quote
 
 
 
 
New Member
Join Date: Aug 2009
Posts: 1
 
      19th Aug 2009
Hi All,

Can you help me in creating the VBS to create the folder with machine name at the specified location

Machine name=xxxxxx

the folder should be created at c:\demo\machine name

Thanks in advance
 
Reply With Quote
 
 
 
 
New Member
Join Date: Dec 2009
Posts: 1
 
      9th Dec 2009
Hi All,

I try to create a subfolder contain following information:

C:\Test\userIDDateTime

Can someone help me below is my code.
Dim oFSO
Dim Retry
Dim PFolder
Dim Pname
Dim FMain
Dim oMain

'Getting Project folder name exist on C drive.
Checkproject (filename)
Function Checkproject (filename)
Dim strRoot
strRoot = "C:\Test"
Set oFSO = CreateObject ("Scripting.FileSystemObject")
'Pname = Inputbox ("Please Enter Your Project Name")
If oFSO.FolderExists (strRoot) Then
Msgbox (strRoot)
Get_User_ID
Get_Date
Get_Time
MakeDir (strPath)
Else
Msgbox ("Please contact your QA or BA to create a project folder name")
End If
End Function
'Get User Initial
Function Get_User_ID
Dim Get_ID
Get_ID = Inputbox ("Please Enter your name initial")
If Get_ID = "" Then
Msgbox ("Initial can not leave blank, please re-enter your initial again")
Get_User_ID
End If
End Function
'Getting Date And Time.
Function Get_Date
Dim MyDate
Dim Short_Date
Dim strDate
MyDate = Date
Short_Date = (Right("00" & Month(Date()),2) & Right("00"&Day(Date()),2) & Right("00"&Year(Date()),2))
'Msgbox ("Your New date is:" & strDate)
End Function
Function Get_Time
Dim MyTime
Dim Short_Time
Dim strTime
MyTime = Time
Short_Time = (Right("00" & Hour(Time()),2) & Right("00"&Minute(Time()),2))
'strTime = Cstr (Short_Time)
'Msgbox ("Your New Time is:" & strTime)
End Function
Function MakeDir (strPath)
Dim strParentPath, objFSO
strPath = Cstr (strRoot & "/" & Get_ID & Short_Date & Short_Time)
Set objFSO = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
strParentPath = objFSO.GetParentFolderName(strPath)
If Not objFSO.FolderExists(strParentPath) Then MakeDir strParentPath
If Not objFSO.FolderExists(strPath) Then objFSO.CreateFolder(strPath)
On Error Goto 0
MakeDir = objFSO.FolderExists(strPath)
End Function
 
Reply With Quote
 
New Member
Join Date: Mar 2010
Posts: 2
 
      16th Mar 2010
Could anyone please help me and see what is wrong with this script.

The whole purpose is to copy from folder A to Folder B . If Folder B doesn't exist craete one and copy all files from A to B.



function copyAllFiles(C:\lab, C:\toFolder)
'this function copies all files in the fromFolder to the toFolder
if the toFolder does not exist it is created
const OverWriteFiles = True
dim objFOS
set objFOS = CreateObject("Scripting.FileSystemObject")
call objFOS.createFolder(C:\toFolder)

call objFSO.CopyFile(C:\lab & "\*.*" ,C:\toFolder ,OverWriteFiles)
end function




I get an error ')' with this.
 
Reply With Quote
 
New Member
Join Date: Mar 2010
Posts: 2
 
      16th Mar 2010
How about this?



function copyAllFiles(fromFolder, toFolder)
'this function copies all files in the fromFolder to the toFolder
if the toFolder does not exist it is created
const OverWriteFiles = True

dim objFOS

set objFOS = CreateObject("Scripting.FileSystemObject")

call objFOS.createFolder(C:\toFolder)


objFSO.CopyFile(fromFOlder & "\*.*" ,toFolder ,OverWriteFiles)

end function
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Set a reference to Microsoft VBScript Regular Expressions(vbscript.dll) cate Microsoft Excel Programming 3 1st Dec 2009 04:07 PM
Unable to call a vbscript within a vbscript Karuna Microsoft Access VBA Modules 1 6th Oct 2008 02:12 PM
How do you create an Outlook application object in my web page using VBscript? Fie Fie Niles Microsoft Outlook 6 23rd Jul 2004 05:06 PM
create vbscript to create rule Noone Important Microsoft Outlook VBA Programming 1 8th Mar 2004 07:15 PM
Create contact with VBScript Greg Martin Microsoft Outlook 0 11th Nov 2003 10:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:42 PM.