[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文件操作] 如何批处理(bat),rar打包当前目录下的指定文件,打包名字可以自定义加文件修改日期

本帖最后由 oyr520 于 2021-11-28 17:19 编辑

使用批处理(bat),rar打包当前目录下的指定文件,打包名字可以自定义加文件修改日期,然后在当前目录下创建user_rar文件夹存放(如果不存在则创建),谢谢解答。

比如:当前目录下有aaa.txt,bbbb.txt,ccccc.txt,ddddd.bin,这些文件修改日期是2021/11/28 11:50,运行批处理后打包这四个txt,打包的名称是DSFC_DSNB_20211128_1150.rar,然后在当前目录下创建user_rar 存放。

回复 17# oyr520
  1. 有效,感谢
复制代码
微信:flashercs
QQ:49908356

TOP

回复 16# flashercs
非常满意,头像支付宝二维码有效吗?想给个小小红包感谢大佬

TOP

  1. @echo off
  2. setlocal EnableDelayedExpansion
  3. cd /d "%~dp0"
  4. @REM set rar="C:\Program Files\WinRAR\WinRAR.exe"
  5. set rar="rar.exe"
  6. set files="2.txt" "cd.txt" "stdout.txt" "stderr.txt"
  7. set comh="include\com.h"
  8. 2>nul md user_rar
  9. for %%A in (%files%) do (
  10.   set "t=%%~tA"
  11.   set "t=!t:-=!"
  12.   set "t=!t:/=!"
  13.   set "t=!t::=!"
  14.   set "t=!t: =_!"
  15.   goto break
  16. )
  17. :break
  18. set stack=0
  19. for /f "usebackq tokens=1*" %%A in (%comh%) do (
  20.   if "!stack!"=="0" (
  21.     if /i "%%B"=="(CUSTOMER_BOARD_TYPE == CUSTOMER_ZY_SP10)" set stack=1
  22.   ) else if "!stack!"=="1" (
  23.     for /f "tokens=1*" %%C in ("%%B") do (
  24.       if "%%C"=="VERSION_NUMBER" (
  25.         set "vn=%%~D"
  26.         goto break2
  27.       )
  28.     )
  29.   )
  30. )
  31. :break2
  32. echo vn=[!vn!]
  33. %rar% a "user_rar\DSFC_DSNB_!vn!_!t!.rar" %files%
  34. endlocal
  35. pause
复制代码
回复 15# oyr520
微信:flashercs
QQ:49908356

TOP

回复 14# flashercs
我明白前面说的意思了 “后面不能有空格
c语言代码里 用空格替代tab”
验证可以了,谢谢大佬
我发现com.h里面有多个#define VERSION_NUMBER        "21102101",只会识别最后一个,但想识别的是下面这个,不知道能实现嘛
#elif (CUSTOMER_BOARD_TYPE == CUSTOMER_ZY_SP10)
#define MODE_NAME "ZY_SP10"
#define MODEL MODEL0
#define VERSION_NUMBER        "S V1.01" //想识别到这个

因为前面宏定义的是
#define CUSTOMER_SUN_SP10                0
#define CUSTOMER_SUN_SP30                1
#define CUSTOMER_ZY_SP10                2 //选的是这个


#define CUSTOMER_BOARD_TYPE CUSTOMER_ZY_SP10 //宏定义有效的是这个#define CUSTOMER_ZY_SP10                2

TOP

回复 13# oyr520


    com.h
  1. /*${.::Com.h} ..............................................................*/
  2. #ifndef Com_h
  3. #define Com_h
  4. //=============macro for function config==============
  5. //=============macro for function config==============
  6. #include "custom_sig.h"
  7. #include "iop_scanner.h"
  8. #include "systemservice.h"
  9. #include "power.h"
  10. #include "user_def.h"
  11. #include "sdk_cfg.h"
  12. #include "user_standby.h"
  13. #include "Display_Srv.h"
  14. #define USERAPP_VOL_MAX (100)
  15. #define USERAPP_VOL_MIN (0)
  16. #define USERAPP_SUB_VOL_MAX (7)//(40)
  17. #define USERAPP_SUB_VOL_MIN (1)
  18. #define CEC_VOL_MAX (100)
  19. //#define DEFAULT_SETTING_APP 0 //usb
  20. #define DEFAULT_SETTING_APP 2 //ARC
  21. //#define DEFAULT_SETTING_APP 4 //aux
  22. #define DEFAULT_SETTING_VOL 34//20
  23. #define DEFAULT_SETTING_EQ eApUserEQ_Mode_FLAT
  24. #define DEFAULT_SETTING_SURROUND eApUserSurround_Mode_OFF
  25. #define DEFAULT_SETTING_DIMMER 2
  26. #define DEFAULT_SETTING_BASS_TRIM 5
  27. #define DEFAULT_SETTING_TREBLE_TRIM 5
  28. #define DEFAULT_SETTING_SURROUND_TRIM 5
  29. //#define AP_DBG
  30. #define ap_printf0(f, a...) LOGX(f, ##a)
  31. #define ap_printf(f, a...) LOGD(f, ##a)
  32. #define ap_printf2(f, a...) LOGDT(f, ##a)
  33. #define ap_printf_E(f, a...) LOGE(f, ##a)
  34. #define printf(f, a...) LOGD(f, ##a)
  35. typedef enum
  36. {
  37.     eUser_TV_UNKNOW = 0,
  38.     eUser_TV_ON,
  39.     eUser_TV_STANDBY,
  40.     eUser_TV_TO_ON,
  41.     eUser_TV_TO_STANDBY
  42. }eUser_TV_Power_t;
  43. typedef enum
  44. {
  45.     UsrHisenseTvSymphonyControl = 0, //TvSymphonyControl   
  46.     UsrHisenseTvSymphonySoundmode = 1, //Soundmode
  47.     UsrHisenseTvSymphonySurroundmode = 2, //Surroundmode
  48.     UsrHisenseTvSymphonyBasslevel = 3, //Dimmer Level
  49.     UsrHisenseTvSymphonyTreblelevel = 4, //Bass Level
  50.     UsrHisenseTvSymphonyDimmer = 5, //Treble Level
  51.     UsrHisenseTvSymphony_max = UsrHisenseTvSymphonyDimmer,
  52. }eUserAppHisenseTvSymphony;
  53. /*${Events::UserAppEvt} ......................................................*/
  54. typedef struct
  55. {
  56. /* protected: */
  57. QEvt super;
  58. /* public: */
  59. //uint8_t scan;
  60. } UserAppEvt;
  61. typedef struct
  62. {
  63. QEvt super;
  64. QActive *pstSender;
  65. UPGRETURN_T *pUPGRETURN_T;
  66. } UserAppUpgradeEvt;
  67. typedef struct
  68. {
  69. QEvt super;
  70. UINT8 User_KeyCode;
  71. UINT8 User_KeyCodeSrc;
  72. stKeyInfo_t *pstKeyInfo_t;
  73. } UserAppKeyEvt;
  74. /*${User Key structure} ......................................................*/
  75. typedef struct
  76. {
  77. UINT8 UserKeyCode;
  78. UINT8 UserKeyCodeSrc;
  79. stKeyInfo_t stKeyInfo;
  80. } stUserKeyInfo_t;
  81. typedef struct
  82. {
  83. int  switch_src_time;
  84. int  power_off_time;
  85. int  power_on_time;
  86. int  burn_log_enable;
  87. } AutoSrcTest_t;
  88. typedef struct
  89. {
  90. int  private_signal_number;
  91. int  private_signal_repeat_time;
  92. } AutoRepeatSignalTest_t;
  93. enum mutestate
  94. {
  95. eMute_off = 0,
  96. eMute_on,
  97. };
  98. typedef enum
  99. {
  100. BT_CONNECT_READY,
  101. BT_CONNECT_SUCCESS,
  102. } BtHintType_e;
  103. typedef enum
  104. {
  105. VA_OFF = 0,
  106. VA_ON,
  107. } eVAStatus_t;
  108. enum channel_src //vic channel detect 0414
  109. {
  110.     channel_RL = 0,
  111.     channel_RL_Sub,
  112.     channel_RL_RLs,
  113.     channel_RL_RLs_Sub,
  114.     channel_default
  115. };
  116. enum surround_sync //vic channel detect 0414
  117. {
  118.     surr_L = 0,
  119. surr_R,
  120. surr_LR,
  121. surr_default
  122. };
  123. /*${AOs::UserApp_ctor} .......................................................*/
  124. void UserApp_ctor(void);
  125. int SendDataBySerial(UINT8 *data ,UINT8 cmd,UINT16 datalength);
  126. int Userapp_Get_System_Memory_Source(void);
  127. /*${AOs::MediaScanner_ctor} .......................................................*/
  128. //void IopScanner_ctor(void);
  129. QActive *UserApp_get(void);
  130. //===== daniel For Trace=====
  131. int UserApp_GetEQStatus(void);
  132. int UserApp_GetSoundModeStatus(void);
  133. /******************************************************************Customer define in here*********************************************************/
  134. #define CUSTOMER_SUN_SP10 0
  135. #define CUSTOMER_SUN_SP30 1
  136. #define CUSTOMER_ZY_SP10 2
  137. #define CUSTOMER_BOARD_TYPE CUSTOMER_ZY_SP10
  138. #define MODEL0 "Demo"
  139. #define MODEL1 "Pre-ES"
  140. #define MODEL2 "ES"
  141. #define MODEL3 "EVT"
  142. #define MODEL4 "DVT"
  143. #define MODEL5 "PVT"
  144. #define MODEL6 "MP"
  145. /********************************SUN SP10****************************************/
  146. #if (CUSTOMER_BOARD_TYPE == CUSTOMER_SUNP_SP10)
  147. #define MODE_NAME "Demo Sun_SP10"
  148. #define MODEL MODEL0
  149. #define VERSION_NUMBER "21102101"
  150. /********************************SUN SP30****************************************/
  151. #elif (CUSTOMER_BOARD_TYPE == CUSTOMER_SUN_SP30)
  152. #define MODE_NAME "Demo Sun_SP30"
  153. #define MODEL MODEL0
  154. #define VERSION_NUMBER "21102101"
  155. //=============GPIO pin function config ==============
  156. #define POWERON_GPIO_PIN (33)
  157. #define POWERON_3V3_GPIO_PIN (31) //gpio31不能使用
  158. #define EXT_BT_RESET_GPIO_PIN (51)
  159. #define POWERON_HDMI_1V3_GPIO_PIN (42)
  160. #define POWERON_WIRELESS_3V3_GPIO_PIN (43)
  161. /********************************SUN SP30****************************************/
  162. #elif (CUSTOMER_BOARD_TYPE == CUSTOMER_ZY_SP10)
  163. #define MODE_NAME "ZY_SP10"
  164. #define MODEL MODEL0
  165. #define VERSION_NUMBER "S V1.01"
  166. #define SDKVERSION "v1.3"
  167. //#define SUPPORT_XEFFECT
  168. #define SUPPORT_EXT_RF //RF_IA9QH5
  169. #ifdef SUPPORT_EXT_RF
  170. #define SYNC_UPGRADE
  171. //#define SUPPORT_TXRX_VER_CHECK
  172. #endif
  173. #define EXT_MCU_IF_CUSTOMER // for extern mcu solution use
  174. #define EXT_BT_UART
  175. #define SUPPORT_UART_MASTER  //uart master mode
  176. #ifdef SUPPORT_UART_MASTER
  177. #define SUPPORT_UART_RINGBUFFER
  178. #endif
  179. #define UART_HY_PROTOCOL 0
  180. #define UART_POLK_DISH_PROTOCOL 1
  181. #define UART_PROTOCOL_TYPE UART_POLK_DISH_PROTOCOL
  182. //=============GPIO pin function config ==============
  183. #define POWERON_GPIO_PIN (44)
  184. #define POWERON_3V3_GPIO_PIN (31) //gpio31不能使用
  185. #define USB_VBUS_GPIO_PIN (21)
  186. #define EXT_BT_RESET_GPIO_PIN (51)
  187. #define EXT_BT_ENABLE_GPIO_PIN (54) //unused
  188. #define POWERON_HDMI_1V3_GPIO_PIN (42) //unused
  189. #define POWERON_WIRELESS_3V3_GPIO_PIN (43) //unused
  190. #define POWERON_LED_GPIO_PIN (14)
  191. #define DEBUG_CTL_GPIO  (34)
  192. #else
  193. #define NAME "HY_MAIN/SP30N"
  194. #define MODEL MODEL0
  195. #define VERSION_NUMBER "21102101"
  196. #endif
  197. #endif /* UserApp_h */
复制代码
微信:flashercs
QQ:49908356

TOP

回复 12# flashercs
修改后,运行会提示无法打开(如下),然后user_rar文件夹是空的没有生成xxx.rar文件,烦请在帮忙看看,谢谢!

D:\test\user_rar\DSFC_DSNB_21102101.rar: 无法打开 _20211129_1921.rar 2.txt cd.txt stdout.txt stderr.txt
!   系统找不到指定的文件。

TOP

本帖最后由 flashercs 于 2021-11-29 16:25 编辑
  1. @echo off
  2. setlocal EnableDelayedExpansion
  3. cd /d "%~dp0"
  4. @REM set rar="C:\Program Files\WinRAR\WinRAR.exe"
  5. set rar="rar.exe"
  6. set files="2.txt" "cd.txt" "stdout.txt" "stderr.txt"
  7. set comh="include\com.h"
  8. 2>nul md user_rar
  9. for %%A in (%files%) do (
  10.   set "t=%%~tA"
  11.   set "t=!t:-=!"
  12.   set "t=!t:/=!"
  13.   set "t=!t::=!"
  14.   set "t=!t: =_!"
  15.   goto break
  16. )
  17. :break
  18. for /f "tokens=1,2*" %%A in ('findstr /irc:"#define  *VERSION_NUMBER" %comh%') do (
  19.   set "vn=%%~C"
  20. )
  21. echo vn=[!vn!]
  22. %rar% a "user_rar\DSFC_DSNB_!vn!_!t!.rar" %files%
  23. endlocal
  24. pause
复制代码
  1. #define VERSION_NUMBER "21102101"
复制代码
后面不能有空格
c语言代码里 用空格替代tab
微信:flashercs
QQ:49908356

TOP

回复 10# flashercs
打包后是这样DSFC_DSNB__20211129_1017.rar,麻烦帮忙看看是什么原因导致的,谢谢!

以下com.h下载链接,如果需要:
https://we.tl/t-QgGy46LeTY

TOP

  1. @echo off
  2. setlocal EnableDelayedExpansion
  3. cd /d "%~dp0"
  4. @REM set rar="C:\Program Files\WinRAR\WinRAR.exe"
  5. set rar="rar.exe"
  6. set files="2.txt" "cd.txt" "stdout.txt" "stderr.txt"
  7. set comh="include\com.h"
  8. 2>nul md user_rar
  9. for %%A in (%files%) do (
  10.   set "t=%%~tA"
  11.   set "t=!t:-=!"
  12.   set "t=!t:/=!"
  13.   set "t=!t::=!"
  14.   set "t=!t: =_!"
  15.   goto break
  16. )
  17. :break
  18. for /f "tokens=1,2*" %%A in ('findstr /irc:"#define  *VERSION_NUMBER  *" %comh%') do (
  19.   set vn=%%~C
  20. )
  21. %rar% a "user_rar\DSFC_DSNB_!vn!_!t!.rar" %files%
  22. endlocal
复制代码
回复 9# oyr520
微信:flashercs
QQ:49908356

TOP

回复 2# flashercs
感谢大佬,如果想要读取com.h文件中#define VERSION_NUMBER     "S V1.01",字符串S V1.01也当成压缩包名称怎么实现呢?
#define VERSION_NUMBER在.h中的行数不是固定的,VERSION_NUMBER 跟字符串之间的空格可能也会变化,include\com.h 文件路径是相对不变的。

也就是压缩包名称从a  -s "user_rar\DSFC_DSNB_!t!.rar" %files% 变为这样a  -s "user_rar\DSFC_DSNB_S V1.01_!t!.rar" %files%

TOP

回复 6# Batcher
我也不太懂怎么处理,目前我的文件都是相同的

TOP

优化一下,把rar路径定义成变量调用
@echo off
setlocal EnableDelayedExpansion
cd /d "%~dp0"
set rar="C:\Program Files\WinRAR\WinRAR.exe"
set files="2.txt" "cd.txt" "stdout.txt" "stderr.txt"
2>nul md user_rar
for %%A in (%files%) do (
  set "t=%%~tA"
  set "t=!t:-=!"
  set "t=!t:/=!"
  set "t=!t::=!"
  set "t=!t: =_!"
  goto break
)
:break
%rar% a  -s "user_rar\DSFC_DSNB_!t!.rar" %files%
endlocal

TOP

回复 1# oyr520


    如果那些文件修改日期不一样咋办?
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

rar.exe修改所在的路径就可以了"C:\Program Files\WinRAR\WinRAR.exe" a

TOP

返回列表