标题: [文件操作] 如何批处理(bat),rar打包当前目录下的指定文件,打包名字可以自定义加文件修改日期 [打印本页]
作者: oyr520 时间: 2021-11-28 14:53 标题: 如何批处理(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 存放。
作者: flashercs 时间: 2021-11-28 17:13
- @echo off
- setlocal EnableDelayedExpansion
- cd /d "%~dp0"
- 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.exe a "user_rar\DSFC_DSNB_!t!.rar" %files%
- endlocal
复制代码
作者: oyr520 时间: 2021-11-28 17:32
回复 2# flashercs
感谢大佬,我测试后能生成文件夹,但文件夹里面没有rar压缩包,请帮忙再看看,谢谢!
我在C盘目录下测试的(固态硬盘没有做分区)
作者: oyr520 时间: 2021-11-28 20:29
尝试改为rar所在的路径也是没有rar压缩包
@echo off
setlocal EnableDelayedExpansion
Rar = "C:\Program Files\WinRAR\WinRAR.exe"
cd /d "%~dp0"
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 "user_rar\DSFC_DSNB_!t!.rar" %files%
endlocal
作者: oyr520 时间: 2021-11-28 21:11
rar.exe修改所在的路径就可以了"C:\Program Files\WinRAR\WinRAR.exe" a
作者: Batcher 时间: 2021-11-28 21:23
回复 1# oyr520
如果那些文件修改日期不一样咋办?
作者: oyr520 时间: 2021-11-28 21:39
优化一下,把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
作者: oyr520 时间: 2021-11-28 21:40
回复 6# Batcher
我也不太懂怎么处理,目前我的文件都是相同的
作者: oyr520 时间: 2021-11-28 22:36
回复 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%
作者: flashercs 时间: 2021-11-29 08:54
- @echo off
- setlocal EnableDelayedExpansion
- cd /d "%~dp0"
- @REM set rar="C:\Program Files\WinRAR\WinRAR.exe"
- set rar="rar.exe"
- set files="2.txt" "cd.txt" "stdout.txt" "stderr.txt"
- set comh="include\com.h"
- 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
- for /f "tokens=1,2*" %%A in ('findstr /irc:"#define *VERSION_NUMBER *" %comh%') do (
- set vn=%%~C
- )
- %rar% a "user_rar\DSFC_DSNB_!vn!_!t!.rar" %files%
- endlocal
复制代码
回复 9# oyr520
作者: oyr520 时间: 2021-11-29 14:26
回复 10# flashercs
打包后是这样DSFC_DSNB__20211129_1017.rar,麻烦帮忙看看是什么原因导致的,谢谢!
以下com.h下载链接,如果需要:
https://we.tl/t-QgGy46LeTY
作者: flashercs 时间: 2021-11-29 16:23
本帖最后由 flashercs 于 2021-11-29 16:25 编辑
- @echo off
- setlocal EnableDelayedExpansion
- cd /d "%~dp0"
- @REM set rar="C:\Program Files\WinRAR\WinRAR.exe"
- set rar="rar.exe"
- set files="2.txt" "cd.txt" "stdout.txt" "stderr.txt"
- set comh="include\com.h"
- 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
- for /f "tokens=1,2*" %%A in ('findstr /irc:"#define *VERSION_NUMBER" %comh%') do (
- set "vn=%%~C"
- )
- echo vn=[!vn!]
- %rar% a "user_rar\DSFC_DSNB_!vn!_!t!.rar" %files%
- endlocal
- pause
复制代码
- #define VERSION_NUMBER "21102101"
复制代码
后面不能有空格
c语言代码里 用空格替代tab
作者: oyr520 时间: 2021-11-29 19:28
回复 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
! 系统找不到指定的文件。
作者: flashercs 时间: 2021-11-29 23:14
回复 13# oyr520
com.h- /*${.::Com.h} ..............................................................*/
-
- #ifndef Com_h
- #define Com_h
-
- //=============macro for function config==============
-
- //=============macro for function config==============
-
- #include "custom_sig.h"
- #include "iop_scanner.h"
- #include "systemservice.h"
- #include "power.h"
- #include "user_def.h"
- #include "sdk_cfg.h"
- #include "user_standby.h"
- #include "Display_Srv.h"
-
- #define USERAPP_VOL_MAX (100)
- #define USERAPP_VOL_MIN (0)
-
- #define USERAPP_SUB_VOL_MAX (7)//(40)
- #define USERAPP_SUB_VOL_MIN (1)
-
- #define CEC_VOL_MAX (100)
-
- //#define DEFAULT_SETTING_APP 0 //usb
- #define DEFAULT_SETTING_APP 2 //ARC
- //#define DEFAULT_SETTING_APP 4 //aux
- #define DEFAULT_SETTING_VOL 34//20
- #define DEFAULT_SETTING_EQ eApUserEQ_Mode_FLAT
- #define DEFAULT_SETTING_SURROUND eApUserSurround_Mode_OFF
- #define DEFAULT_SETTING_DIMMER 2
- #define DEFAULT_SETTING_BASS_TRIM 5
- #define DEFAULT_SETTING_TREBLE_TRIM 5
- #define DEFAULT_SETTING_SURROUND_TRIM 5
-
- //#define AP_DBG
- #define ap_printf0(f, a...) LOGX(f, ##a)
- #define ap_printf(f, a...) LOGD(f, ##a)
- #define ap_printf2(f, a...) LOGDT(f, ##a)
- #define ap_printf_E(f, a...) LOGE(f, ##a)
- #define printf(f, a...) LOGD(f, ##a)
-
-
- typedef enum
- {
- eUser_TV_UNKNOW = 0,
- eUser_TV_ON,
- eUser_TV_STANDBY,
- eUser_TV_TO_ON,
- eUser_TV_TO_STANDBY
- }eUser_TV_Power_t;
-
- typedef enum
- {
- UsrHisenseTvSymphonyControl = 0, //TvSymphonyControl
- UsrHisenseTvSymphonySoundmode = 1, //Soundmode
- UsrHisenseTvSymphonySurroundmode = 2, //Surroundmode
- UsrHisenseTvSymphonyBasslevel = 3, //Dimmer Level
- UsrHisenseTvSymphonyTreblelevel = 4, //Bass Level
- UsrHisenseTvSymphonyDimmer = 5, //Treble Level
- UsrHisenseTvSymphony_max = UsrHisenseTvSymphonyDimmer,
- }eUserAppHisenseTvSymphony;
-
- /*${Events::UserAppEvt} ......................................................*/
- typedef struct
- {
- /* protected: */
- QEvt super;
-
- /* public: */
- //uint8_t scan;
- } UserAppEvt;
-
- typedef struct
- {
- QEvt super;
- QActive *pstSender;
- UPGRETURN_T *pUPGRETURN_T;
- } UserAppUpgradeEvt;
-
-
- typedef struct
- {
- QEvt super;
- UINT8 User_KeyCode;
- UINT8 User_KeyCodeSrc;
- stKeyInfo_t *pstKeyInfo_t;
- } UserAppKeyEvt;
-
-
-
- /*${User Key structure} ......................................................*/
- typedef struct
- {
- UINT8 UserKeyCode;
- UINT8 UserKeyCodeSrc;
- stKeyInfo_t stKeyInfo;
- } stUserKeyInfo_t;
-
- typedef struct
- {
- int switch_src_time;
- int power_off_time;
- int power_on_time;
- int burn_log_enable;
- } AutoSrcTest_t;
-
-
- typedef struct
- {
- int private_signal_number;
- int private_signal_repeat_time;
- } AutoRepeatSignalTest_t;
-
- enum mutestate
- {
- eMute_off = 0,
- eMute_on,
-
- };
-
- typedef enum
- {
- BT_CONNECT_READY,
- BT_CONNECT_SUCCESS,
- } BtHintType_e;
-
- typedef enum
- {
- VA_OFF = 0,
- VA_ON,
- } eVAStatus_t;
-
- enum channel_src //vic channel detect 0414
- {
- channel_RL = 0,
- channel_RL_Sub,
- channel_RL_RLs,
- channel_RL_RLs_Sub,
- channel_default
-
- };
-
- enum surround_sync //vic channel detect 0414
- {
- surr_L = 0,
- surr_R,
- surr_LR,
- surr_default
-
- };
-
- /*${AOs::UserApp_ctor} .......................................................*/
- void UserApp_ctor(void);
- int SendDataBySerial(UINT8 *data ,UINT8 cmd,UINT16 datalength);
- int Userapp_Get_System_Memory_Source(void);
-
-
-
- /*${AOs::MediaScanner_ctor} .......................................................*/
- //void IopScanner_ctor(void);
-
-
- QActive *UserApp_get(void);
-
- //===== daniel For Trace=====
- int UserApp_GetEQStatus(void);
- int UserApp_GetSoundModeStatus(void);
-
-
- /******************************************************************Customer define in here*********************************************************/
- #define CUSTOMER_SUN_SP10 0
- #define CUSTOMER_SUN_SP30 1
- #define CUSTOMER_ZY_SP10 2
-
-
- #define CUSTOMER_BOARD_TYPE CUSTOMER_ZY_SP10
-
- #define MODEL0 "Demo"
- #define MODEL1 "Pre-ES"
- #define MODEL2 "ES"
- #define MODEL3 "EVT"
- #define MODEL4 "DVT"
- #define MODEL5 "PVT"
- #define MODEL6 "MP"
-
- /********************************SUN SP10****************************************/
- #if (CUSTOMER_BOARD_TYPE == CUSTOMER_SUNP_SP10)
- #define MODE_NAME "Demo Sun_SP10"
- #define MODEL MODEL0
- #define VERSION_NUMBER "21102101"
-
- /********************************SUN SP30****************************************/
- #elif (CUSTOMER_BOARD_TYPE == CUSTOMER_SUN_SP30)
- #define MODE_NAME "Demo Sun_SP30"
- #define MODEL MODEL0
- #define VERSION_NUMBER "21102101"
-
- //=============GPIO pin function config ==============
- #define POWERON_GPIO_PIN (33)
- #define POWERON_3V3_GPIO_PIN (31) //gpio31不能使用
- #define EXT_BT_RESET_GPIO_PIN (51)
- #define POWERON_HDMI_1V3_GPIO_PIN (42)
- #define POWERON_WIRELESS_3V3_GPIO_PIN (43)
-
- /********************************SUN SP30****************************************/
- #elif (CUSTOMER_BOARD_TYPE == CUSTOMER_ZY_SP10)
- #define MODE_NAME "ZY_SP10"
- #define MODEL MODEL0
- #define VERSION_NUMBER "S V1.01"
- #define SDKVERSION "v1.3"
-
- //#define SUPPORT_XEFFECT
- #define SUPPORT_EXT_RF //RF_IA9QH5
-
- #ifdef SUPPORT_EXT_RF
- #define SYNC_UPGRADE
- //#define SUPPORT_TXRX_VER_CHECK
- #endif
-
- #define EXT_MCU_IF_CUSTOMER // for extern mcu solution use
- #define EXT_BT_UART
- #define SUPPORT_UART_MASTER //uart master mode
-
- #ifdef SUPPORT_UART_MASTER
- #define SUPPORT_UART_RINGBUFFER
- #endif
-
- #define UART_HY_PROTOCOL 0
- #define UART_POLK_DISH_PROTOCOL 1
-
- #define UART_PROTOCOL_TYPE UART_POLK_DISH_PROTOCOL
-
- //=============GPIO pin function config ==============
- #define POWERON_GPIO_PIN (44)
- #define POWERON_3V3_GPIO_PIN (31) //gpio31不能使用
- #define USB_VBUS_GPIO_PIN (21)
- #define EXT_BT_RESET_GPIO_PIN (51)
- #define EXT_BT_ENABLE_GPIO_PIN (54) //unused
- #define POWERON_HDMI_1V3_GPIO_PIN (42) //unused
- #define POWERON_WIRELESS_3V3_GPIO_PIN (43) //unused
- #define POWERON_LED_GPIO_PIN (14)
- #define DEBUG_CTL_GPIO (34)
-
- #else
- #define NAME "HY_MAIN/SP30N"
- #define MODEL MODEL0
- #define VERSION_NUMBER "21102101"
- #endif
-
- #endif /* UserApp_h */
复制代码
作者: oyr520 时间: 2021-11-30 00:42
回复 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
作者: flashercs 时间: 2021-11-30 10:53
- @echo off
- setlocal EnableDelayedExpansion
- cd /d "%~dp0"
- @REM set rar="C:\Program Files\WinRAR\WinRAR.exe"
- set rar="rar.exe"
- set files="2.txt" "cd.txt" "stdout.txt" "stderr.txt"
- set comh="include\com.h"
- 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
- set stack=0
- for /f "usebackq tokens=1*" %%A in (%comh%) do (
- if "!stack!"=="0" (
- if /i "%%B"=="(CUSTOMER_BOARD_TYPE == CUSTOMER_ZY_SP10)" set stack=1
- ) else if "!stack!"=="1" (
- for /f "tokens=1*" %%C in ("%%B") do (
- if "%%C"=="VERSION_NUMBER" (
- set "vn=%%~D"
- goto break2
- )
- )
- )
- )
- :break2
- echo vn=[!vn!]
- %rar% a "user_rar\DSFC_DSNB_!vn!_!t!.rar" %files%
- endlocal
- pause
复制代码
回复 15# oyr520
作者: oyr520 时间: 2021-11-30 12:09
回复 16# flashercs
非常满意,头像支付宝二维码有效吗?想给个小小红包感谢大佬
作者: flashercs 时间: 2021-11-30 14:20
回复 17# oyr520 复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |