Create a timestamp folder with today's date and time and copy some folder to it

好久不见. 提交于 2019-12-13 09:16:26

问题


I'm trying to create a folder in windows with current timestamp details and copy some folder to it. I tried as below:

   bat 'for /f "tokens=2-4 delims=/ " %%i in ("%date%") do SET today_fname=%%i_%%j_%%k'
    bat 'for /f "tokens=2-4 delims=/ " %%i in ("%date%") do md today_fname'
    bat 'cd %today_fname%'
    bat 'copy "C:/Program Files (x86)/Jenkins/workspace/jenkins Pipeline/application/bin/Debug/netcoreapp2.1/os/publish"'

It ends up creating a folder with a timestamp name and copying the folder contains to current directory instead of Cd to newly created folder I'm trying to create a folder with a name 05_14_18_7_31 and copy the contains present in this location C:/Program Files (x86)/Jenkins/workspace/jenkins Pipeline/application/bin/Debug/netcoreapp2.1/os/publish to 05_14_18_7_31


回答1:


Here is something you can try:

@echo off
rem Create datestamp:
set "datestamp=%date:~4,-8%_%date:~7,-5%_%date:~12,2%"
rem Request for me, if you are not using `dd/mm/yy` format, to provide another script for your occassion.
rem Create timestamp:
set "timestamp=%time:~0,2%_%time:~3,2%"
rem Create folder:
md %datestamp%_%timestamp%
xcopy /E "C:/Program Files (x86)/Jenkins/workspace/jenkins Pipeline/application/bin/Debug/netcoreapp2.1/os/publish" "%datestamp%_%timestamp%"

Hope this helps!



来源:https://stackoverflow.com/questions/53000463/create-a-timestamp-folder-with-todays-date-and-time-and-copy-some-folder-to-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!