批处理到vb.net建议 [英] batch to vb.net advice
问题描述
大家好,
我对批处理非常好,但对于要在vb.net中使用的命令类型却不是那么好,它与批处理脚本具有相同的效果.
我知道我可以在vb.net中使用批处理代码,并且知道可以调用.bat文件,但这不是我想要的.
应该可以使用vb.net代码执行与批处理代码相同的操作.
这是我得到的正确批处理文件.
它的作用是检查文件夹是否存在,如果不包含今天的日期.
例如F:\ Backups \ Backups \ 2012-01-10
然后将打开文件夹
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%"
这是我正在研究的另一个项目中的一些vb.net代码片段
它会查看文件夹是否存在,如果不存在,则创建一个文件夹
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
'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
推荐答案
请将其作为提示而不是作为问题
please post it as tip not as question
这篇关于批处理到vb.net建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!