 |
| Access VBA Discuss using VBA for Access programming. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 1st, 2007, 08:22 AM
|
|
Registered User
|
|
Join Date: Mar 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
how to split string
Hi,
i want to know how to create a directory with the current date as the name.
For eg: i want to create a directory as Thu 03/01/2007.
As this is the output occurs for the command date /T
in the MS DOS
Can any one help me how to create a directory by getting the date from the system in windows
|
|

March 1st, 2007, 08:56 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
I can tell you you won't get a folder name with reserved characters like "Thu 03/01/2007." You will have to do "Thu 03_01_2007" instead. This is standard.
If you are setting up folders for future reference, I would suggest this naming convention since the folders will always apear in sequence:
2007_03_01 Thu
Anyway, assuming you have rights, just do this:
Dim dtDate As Date
Dim dtDay As Integer
Dim sWDay, sFolder As String
Dim sM, sD As String
Dim objFSO, objFolder As Variant (or don't put a type)
dtDate = Date()
dtDay = DatePart("w", dtDate)
sWDay = Left(WeekdayName(dtDay), 3)
sM = DatePart("m", dtDate)
sD = DatePart("d", dtDate)
Select Case sM
Case "1"
sM = "01"
Case "2"
sM = "02"
Case "3"
sM = "03"
Case "4"
sM = "04"
Case "5"
sM = "05"
Case "6"
sM = "06"
Case "7"
sM = "07"
Case "8"
sM = "08"
Case "9"
sM = "09"
End Select
Select Case sD
Case "1"
sD = "01"
Case "2"
sD = "02"
Case "3"
sD = "03"
Case "4"
sD = "04"
Case "5"
sD = "05"
Case "6"
sD = "06"
Case "7"
sD = "07"
Case "8"
sD = "08"
Case "9"
sD = "09"
End Select
sFolder = "C:\MyFolders\" & sWDay & " " & sM & "_" & sD & "_" & DatePart("yyyy", dtDate)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder(sFolder)
Did that help?
mmcdonal
|
|

March 1st, 2007, 08:59 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
You probably want to make sure the the C:\MyFolders folder already exists. I ran this without that folder just using C:\, but I think it will work if it is creating two levels.
mmcdonal
|
|

March 1st, 2007, 09:04 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
Sorry, I didn't address this issue: "As this is the output occurs for the command date /T in the MS DOS".
I am assuming when you say MS DOS, you are referring to the command window in Windows, which is a 32 bit app, not DOS. This 32 bit app is referred to as Comspec in all versions of Windows. So here is the code for running "date /T" in compsec... if that is what you want:
Set objShell = CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec _
("%comspec% /c date /T")
Is that what you wanted?
mmcdonal
|
|

March 2nd, 2007, 12:57 AM
|
|
Registered User
|
|
Join Date: Mar 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
thanks for ur reply...............
but i din get the expected output...........
I am working in Windows XP
My problem is::::
If i execute the command "date /T" means i m getting the output as "Fri 03/02/2007". I want to write a automation script for my project. I have written a script that will get executed every day. In order to know the output i have to store the output in a folder with the corresponding date of execution. The automation script is written using batch commands(i.e. it is a .bat file)
I want to store the output in a folder with the date
Help me please................
|
|

March 2nd, 2007, 08:40 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
Do you mean something like this:
Set objShell = WScript.CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec("%comspec% /c ipconfig.exe /all")
Do Until objExecObject.StdOut.AtEndOfStream
strLine = objExecObject.StdOut.ReadLine()
strIP = InStr(strLine, "Address")
sDHCP = InStr(strLine, "Dhcp Enabled")
sWINS = InStr(strLine, "Primary WINS Server")
If strIP <> 0 Then
IPArray = Split(strLine, ":")
strAddress = IPArray(1)
End If
If sDHCP <> 0 Then
DHArray = Split(strLine, ":")
sEnable = DHArray(1)
End If
If sWINS <> 0 Then
WINArray = Split(strLine, ":")
sPWS = WINArray(1)
End If
This takes the values from the screen output of ipconfig, for example. Does this get you started? You can call a script from your .bat file, or you can do everything in the .vbs file that you are doing in the .bat file instead.
mmcdonal
|
|

March 6th, 2007, 07:22 AM
|
|
Registered User
|
|
Join Date: Mar 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
no i want the thing to be in .bat format only
|
|

March 6th, 2007, 09:07 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
|
|
Then why did you post in the Access VBA forum?
mmcdonal
|
|

June 20th, 2007, 02:07 AM
|
|
Registered User
|
|
Join Date: Jun 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
************* BEGIN CODE SAMPLE *************
FOR /F "tokens=1-4 delims=/-. " %%P IN ('date /t') DO SET D=%%S_%%R_%%Q %%P
cd cd temp
md "%D%"
************* END CODE SAMPLE *************
HTH.
Regards,
Richard Hauer
===================
5 Limes Pty Limited
Sydney, Australia
www.5Limes.com.au
|
|

June 20th, 2007, 02:09 AM
|
|
Registered User
|
|
Join Date: Jun 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
sorry - typo put an extra "cd" in my last post
HTH.
Richard Hauer
===================
5 Limes Pty Limited
Sydney, Australia
www.5Limes.com.au
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| string split |
vidhya |
XSLT |
1 |
August 10th, 2005 04:53 AM |
| How to split a string |
lily611 |
General .NET |
5 |
March 18th, 2005 01:16 PM |
| string split by : |
crmpicco |
Classic ASP Basics |
3 |
February 10th, 2005 07:49 AM |
| String.Split |
bbhill |
General .NET |
2 |
April 10th, 2004 05:53 PM |
|
 |