Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
hey guys,
i a very good with batch and all that but not so good with the types of commands that i would like to use in vb.net that will have the same effect as my batch script.
I do know that i can use batch code in vb.net and i know i can call the .bat file but this is not what i want.
it shoud be posible to use vb.net code to do the same thing as the batch code.

This is the correct batch file i got.
what it does is check if a folder exist, if not make one with the todays date.
eg F:\Backups\Backups\2012-01-10
then it will open the folder
:: <summary>
::   This Script will make a Dir Backups\"Corrent Date"
::   YYYY-MM-DD
::   HH:MM:SS
:: </summary>
:: <remarks></remarks>
@echo off
REM <Format Settings>
:: ***********************************
set YourDateFormat=%%D-%%C-%%B
set YourTimeDormat=
REM Add time to the dir? 0=Off 1=On (to be tested)
set TimeDir=0
REM This is the name of the folder. (No Spacers)
set backupfolder=Backups
:: SEE LINE 43
REM </Format Settings>
:: ***********************************

REM Get the date to var
@for /F "tokens=1,2,3,4 delims=/ " %%A in ('Date /t') do @(
set DayW=%%A
set Day=%%B
set Month=%%C
set Year=%%D
set AllDate=%YourDateFormat%
::set AllDate=%%D-%%C-%%B
REM AllDate=%%D-%%C-%%B-%%A
)
REM Get the time to var
@for /F "tokens=1,2,3 delims=:,. " %%A in ('echo %time%') do @(
set Hour=%%A
set Min=%%B
set Sec=%%C
set AllDatem=%%A-%%B 
)
REM Get the AM/PM to var
@for /F "tokens=3 delims=: " %%A in ('time /t ') do @(
set AMPM=%%A
)

:: This is your Dir String
:: ***********************************
set dir=%cd%\%backupfolder%\%AllDate%\
:: ***********************************

::echo Your Dir is :  %dir%
::pause

REM You can use %AllDatem% %AMPM%
md "%dir%"
::echo Your Dir is:   %dir%
%SystemRoot%\explorer.exe "%dir%"

this is some vb.net code snippets that is from another project that i am working on
it will see if a folder exist and if not make a folder
VB
    'check if folder exist if not make folder
    Public Function CreateIfNotExists(ByVal sFolderPath As String) As Boolean
        Try
            Dim exists As Boolean = False
            exists = My.Computer.FileSystem.DirectoryExists(sFolderPath)
            If Not exists Then
                My.Computer.FileSystem.CreateDirectory(sFolderPath)
                Return True
            Else
                Return True
            End If
        Catch ex As Exception
            Return False
        End Try
    End Function

Sub md()
Dim sFolderPath As String = "C:\test\" : CreateIfNotExists()

End Sub
Posted
Updated 9-Jan-12 19:48pm
v2
Comments
Sergey Alexandrovich Kryukov 10-Jan-12 0:30am    
This is not a question, what do your want and -- importantly -- why?
Please use "Improve question" above.
--SA

1 solution

please post it as tip not as question
 
Share this answer
 
Comments
Member 8327439 10-Jan-12 17:48pm    
Sorry if i wasent clear.
i am having trubble with the vb.net part.
I have tryed to make a start.
what i need to know is how to get the current time and store it into a string in this format yyyy-mm-dd
when you read the batch you may see that i could add the time in there as well.

so all i need is some help with the date to string part, i am sure i can work it out from there.

but your right i should of but a bit more thinking into what i was typing.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900