• 常用的Windows批处理


     
    切换执行路径
    如果不换盘的话:
    cd xxx
    换盘:
    cd /d xxx
     
    获取当前日期

    编写Windows批处理时经常会需要使用到日期和时间作为文件名,所以是非常重要的。

    如何获取日期呢?
    格式:  %date%
    结果:  2012-07-31

    如何获取时间呢?
    格式:  %time%
    结果:  10:21:21.68

    这是获取的系统标准格式的日期和时间,但是有时候我们需要使用规定的格式,怎么办呢?

    格式:   %date:~x,y%以及%time:~x,y%
    说明:   x是开始位置,y是取得字符数

    比如说我要获取完整的日期和时间,
    格式:   %date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%
    结果:   20120731111039
    但是如果时间早于10点,那么只显示日期不显示时间,如:20120731,如何解决呢?
    格式:   %date:~0,4%%date:~5,2%%date:~8,2%0%time:~1,1%%time:~3,2%%time:~6,2%
    结果:   20120731052539

    这样就达到我们的目标,成功的得到日期和时间了。

    批处理文件同时打开多个文件夹

    2006-09-23 00:05:36|  分类: 电脑日常应用 |  标签:批处理   |举报 |字号大中小 订阅



    打开记事本,输入以下内容: 
    (先假定,你要同时打开 C盘,D盘下的flash文件夹,还有C盘的system32文件夹) 

    explorer.exe /n,C: 
    explorer.exe /n,C:windows 

    explorer.exe /n,D:flash

    删除文件 文件夹

    @echo off

    rem 如果是磁盘符,最好加上符合

    set DESC_PATH=E:

    rem 只需要部分字符

    set file_str=rar

    set folder_str=hi6620

    rem 控制开关

    set search_file=1

    set search_folder=1

    set del_flag=1

    rem 临时文件,备份记录用,不用修改

    set file_log=file.log

    set folder_log=folder.log

    set workspace=%CD%

    rem 只查找文件

    if %search_file%==1 (

        cd /d %DESC_PATH%

        rem 搜寻子目录,排除文件夹

        dir /b /s /a-d | find "%file_str%" > %workspace%\%file_log%

    )

    rem 只查找目录

    if %search_folder%==1 (

        cd /d %DESC_PATH%

        rem 目的:希望不统计文件在内

        dir /b /s /a-a | find "%folder_str%" > %workspace%\%folder_log%

    )

    rem 待考虑引入输入判断yes or no 决定是否删除,这样更人性

    echo Warning:%workspace%\%file_log% and %folder_log%, please check ...

    pause

    cd /d %workspace%

    if %del_flag%==1 (

        if %search_file%==1 (

            for /f %%i in (%workspace%\%file_log%) do  (

                if exist %%i del %%i

            )

        )

        if %search_folder%==1 (

            for /f %%i in (%workspace%\%folder_log%) do  (

                if exist %%i rd /s /q %%i

            )

        )

    )

    cd /d %workspace%

    pause  

    -----------自动编译打包程序的Windows命令

    SET dotNetFrameworkPath=C:/WINDOWS/Microsoft.NET/Framework/v4.0.30319
    SET dotNetFrameworkDrive=c:

    REM if exist D:WorkTempRelease
    del /f /s /q D:WorkTempRelease
    rd D:WorkTempRelease
    echo ----------------清理完毕,开始生成--------------------------


    if not exist %ibasWorkSpace%ReleaseServices md %ibasWorkSpace%ReleaseServices
    rem============================IISPublish工程===========================
    cd %dotNetFrameworkPath%
    %dotNetFrameworkDrive%
    REM ----------创建对应的模块的目录 +svc文件
    msbuild %ibasSourceCode_TieLong%BizSys.ContainerManagement.ServiceBizSys.ContainerManagement.Service.csproj /t:ResolveReferences;Compile /t:_WPPCopyWebApplication /p:Configuration=Release /p:_ResolveReferenceDependencies=true /p:WebProjectOutputDir=%ibasWorkSpace%ReleaseServicesCMService >>%ibasWorkSpace%/Release/PublishLog.txt

    msbuild %ibasSourceCode_TieLong%BizSys.SystemCenter.ServiceBizSys.SystemCenter.Service.csproj /t:ResolveReferences;Compile /t:_WPPCopyWebApplication /p:Configuration=Release /p:_ResolveReferenceDependencies=true /p:WebProjectOutputDir=%ibasWorkSpace%ReleaseServicesSCService >>%ibasWorkSpace%/Release/PublishLog.txt

    @echo off


    REM ----------发布启动壳中的zip文件+xap文件+bin 文件

    copy /y %ibasSourceCode_TieLong%BizSys.SystemCenter.ServiceClientBinBSUi.SystemApplicationCenter.Silverlight.zip %ibasWorkSpace%ReleaseServicesSCServiceClientBin >%ibasWorkSpace%/Release/CopyFileLog.txt
    copy /y %ibasSourceCode_TieLong%BizSys.SystemCenter.ServiceClientBinBSUi.ApprovalProcess.Silverlight.zip %ibasWorkSpace%ReleaseServicesSCServiceClientBin >>%ibasWorkSpace%/Release/CopyFileLog.txt
    copy /y %ibasSourceCode_TieLong%BizSys.SystemCenter.ServiceClientBinBSUi.BusinessSystemCenter.Silverlight.xap %ibasWorkSpace%ReleaseServicesSCServiceClientBin >>%ibasWorkSpace%/Release/CopyFileLog.txt
    copy /y %ibasSourceCode_TieLong%BizSys.SystemCenter.Servicein*.* %ibasWorkSpace%ReleaseServicesSCServicein >>%ibasWorkSpace%/Release/CopyFileLog.txt


    echo waiting for clear the webConfig files ...... >>%ibasWorkSpace%/Release/PublishLog.txt

    del /f /s /q D:WorkTempReleaseServicesWeb.config
    del /f /s /q D:WorkTempReleaseServicesSCServiceClientBin*.ClientConfig
    del /f /s /q D:WorkTempReleaseServicesSCService*.html
    del /f /s /q D:WorkTempReleaseServicesSCService*.aspx
    del /f /s /q D:WorkTempReleaseServicesSCService*.js
    del /f /s /q D:WorkTempReleaseServicesSCService*.bat
    del /f /s /q D:WorkTempReleaseServicesSCService*.config
    del /q D:WorkTempReleaseServicesSCServiceHandler
    del /q D:WorkTempReleaseServicesSCServiceDataService
    rd D:WorkTempReleaseServicesSCServiceHandler
    rd D:WorkTempReleaseServicesSCServiceDataService
    del /f /s /q D:WorkTempReleaseServicesCMService*.xml
    del /q D:WorkTempReleaseServicesCMServiceDataService
    rd /q D:WorkTempReleaseServicesCMServiceDataService
    REM copy /y %ibasSourceCode_TieLong%BizSys.SystemCenter.ServiceWeb.config %ibasWorkSpace%ReleaseServicesSCServiceWeb.config >>%ibasWorkSpace%/Release/CopyFileLog.txt


    cd /d D:WorkTempReleaseServices
    "%ibasTools%7zip7z.exe" a -tzip Services%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%.zip -r *.*

    explorer.exe D:WorkTempRelease
    echo webConfig files has been cleared and the start Ptoject's config File has copied.. >>%ibasWorkSpace%/Release/PublishLog.txt
    echo. & pause

    7z压缩工具

    http://url.cn/bTu4W8

  • 相关阅读:
    vs中nodejs代码 resharper 提示 ECMAScript2015 Feature. your Current language level is ECMAScript5的解决办法
    port: ${SERVER_PORT:9190} #首先取环境变量,如果环境变量中没有,就取 9190 这个固定值
    SpringbBoot之JPA批量更新
    Linq To Object多字段组合唯一校验
    LINQ获取两个List的交集
    Linq实现分组后取最大(小)值
    Maven:浅析依赖(dependency)关系中 scope 的含义
    Source roots (or source folders) Test source roots (or test source folders; shown as rootTest)Resource rootsTest resource roots
    Parameter 0 of method sqlSessionTemplate in org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration required a single bean, but 2 were found:
    sping boot/cloud配置文件 on 读取为true
  • 原文地址:https://www.cnblogs.com/micro-chen/p/4115275.html
Copyright © 2020-2023  润新知