Windows 使用批处理程序自动运行批处理并删除日志文件上的第二行

Windows 使用批处理程序自动运行批处理并删除日志文件上的第二行,windows,batch-file,backup,xcopy,autorun,Windows,Batch File,Backup,Xcopy,Autorun,我正在制作一个新的批处理程序,将文件夹(及其子文件夹和子文件)从我的外部硬盘复制到我的家用笔记本电脑,并复制到我工作中的工作桌面,前提是其中有一个比计算机硬盘更新的文件。它在工作时循环在我的后台运行它(运行时总是更新)。 它创建一个实时日志文件,其中包含复制文件的“编号”和“名称”列表以及更新的“时间” 但我有两个问题: 1st-插入电脑后如何自动运行(家用笔记本电脑是具有管理员权限的Windows 10,而工作桌面是不具有管理员权限的Windows 7) 2nd-它显示并记录了“复制的0个文件

我正在制作一个新的批处理程序,将文件夹(及其子文件夹和子文件)从我的外部硬盘复制到我的家用笔记本电脑,并复制到我工作中的工作桌面,前提是其中有一个比计算机硬盘更新的文件。它在工作时循环在我的后台运行它(运行时总是更新)。 它创建一个实时日志文件,其中包含复制文件的“编号”和“名称”列表以及更新的“时间”

但我有两个问题:

1st-插入电脑后如何自动运行(家用笔记本电脑是具有管理员权限的Windows 10,而工作桌面是不具有管理员权限的Windows 7)

2nd-它显示并记录了“复制的0个文件”,我可以通过第二批在日志文件中删除这些文件,但保留在第二行下面的日期和时间。。。如何删除它并保存日志

有一个“Backuper Looper.bat”

@echo off 
setlocal EnableDelayedExpansion

REM Change the characters from batch language to normal language (with accent, etc)
for /f "tokens=2 delims=:." %%x in ('chcp') do set cp=%%x
chcp 1252>nul

REM This choses if the External HD is pluged in my Home Laptop or Work Desktop...
IF EXIST C:\Users\"Hubert Pires"\Pictures\Produções\Trabalhos goto :Home
If errorlevel 4 goto :exit
goto :Work
chcp %cp%>nul

rem -------------------------------------------------------------------------


rem ----------a----------a----------a----------a----------a----------a-------a

REM This will display and make a text row on log when starting the program (where is pluged in?)
:Home
Echo External HD Pluged your Home Laptop %date% %time% >_ && type _ && type _ >> Backuper_log.txt
TIMEOUT 1
goto :a

:a

for /f "tokens=2 delims=:." %%x in ('chcp') do set cp=%%x
chcp 1252>nul

xcopy F:\Trabalho\Cartazes C:\Users\"Hubert Pires"\Pictures\Produções\Trabalhos /s /e /d /y >_ && type _ && type _ >> Backuper_log.txt  && echo %date% %time% >_ && type _ && type _ >> Backuper_log.txt

if errorlevel 4 goto :b 
if errorlevel 2 goto abort 

rem findstr /v /i /c:"0 File(s)" Backuper_log.txt >Backuper_log.txt (THIS WAS JUST A TEST)
rem findstr /v /c:"0 File(s)"                                       (THIS WAS JUST A TEST)
del _
call "cmd /c start /min Logger.bat"

chcp %cp%>nul
goto :a
rem ----------a----------a----------a----------a----------a----------a-------a


rem ----------b----------b----------b----------b----------b----------b-------b

REM This will display and make a text row on log when starting the program (where is pluged in?)
:Work
Echo External HD Pluged your Work Desktop %date% %time%
TIMEOUT 1
goto :b

:b

for /f "tokens=2 delims=:." %%x in ('chcp') do set cp=%%x
chcp 1252>nul

xcopy F:\Trabalho\Cartazes C:\Users\hjdungen\cartazes /s /e /d /y >_ && type _ && type _ >> Backuper_log.txt  && echo %date% %time% >_ && type _ && type _ >> Backuper_log.txt

if errorlevel 4 goto :b 
if errorlevel 2 goto abort 

del _
call "cmd /c start /min Logger.bat"

chcp %cp%>nul
goto :b
rem ----------b----------b----------b----------b----------b----------b-------b


rem ----------ABORT----------ABORT----------ABORT----------ABORT---------ABORT
:abort 
echo You pressed CTRL+C to end the copy operation. 
goto exit 
rem ----------ABORT----------ABORT----------ABORT----------ABORT---------ABORT


rem ----------EXIT----------EXIT----------EXIT----------EXIT--------------EXIT
:exit 
findstr /v /i /c:"0 File(s)" Backuper_log.txt > Backuper_log2.txt
type Backuper_log2.txt > Backuper_log.txt
del Backuper_log2.txt
exit
这是“Logger.bat”:

@echo off 
setlocal EnableDelayedExpansion

REM Change the characters from batch language to normal language (with accent, etc)
for /f "tokens=2 delims=:." %%x in ('chcp') do set cp=%%x
chcp 1252>nul

REM This choses if the External HD is pluged in my Home Laptop or Work Desktop...
IF EXIST C:\Users\"Hubert Pires"\Pictures\Produções\Trabalhos goto :Home
If errorlevel 4 goto :exit
goto :Work
chcp %cp%>nul

rem -------------------------------------------------------------------------


rem ----------a----------a----------a----------a----------a----------a-------a

REM This will display and make a text row on log when starting the program (where is pluged in?)
:Home
Echo External HD Pluged your Home Laptop %date% %time% >_ && type _ && type _ >> Backuper_log.txt
TIMEOUT 1
goto :a

:a

for /f "tokens=2 delims=:." %%x in ('chcp') do set cp=%%x
chcp 1252>nul

xcopy F:\Trabalho\Cartazes C:\Users\"Hubert Pires"\Pictures\Produções\Trabalhos /s /e /d /y >_ && type _ && type _ >> Backuper_log.txt  && echo %date% %time% >_ && type _ && type _ >> Backuper_log.txt

if errorlevel 4 goto :b 
if errorlevel 2 goto abort 

rem findstr /v /i /c:"0 File(s)" Backuper_log.txt >Backuper_log.txt (THIS WAS JUST A TEST)
rem findstr /v /c:"0 File(s)"                                       (THIS WAS JUST A TEST)
del _
call "cmd /c start /min Logger.bat"

chcp %cp%>nul
goto :a
rem ----------a----------a----------a----------a----------a----------a-------a


rem ----------b----------b----------b----------b----------b----------b-------b

REM This will display and make a text row on log when starting the program (where is pluged in?)
:Work
Echo External HD Pluged your Work Desktop %date% %time%
TIMEOUT 1
goto :b

:b

for /f "tokens=2 delims=:." %%x in ('chcp') do set cp=%%x
chcp 1252>nul

xcopy F:\Trabalho\Cartazes C:\Users\hjdungen\cartazes /s /e /d /y >_ && type _ && type _ >> Backuper_log.txt  && echo %date% %time% >_ && type _ && type _ >> Backuper_log.txt

if errorlevel 4 goto :b 
if errorlevel 2 goto abort 

del _
call "cmd /c start /min Logger.bat"

chcp %cp%>nul
goto :b
rem ----------b----------b----------b----------b----------b----------b-------b


rem ----------ABORT----------ABORT----------ABORT----------ABORT---------ABORT
:abort 
echo You pressed CTRL+C to end the copy operation. 
goto exit 
rem ----------ABORT----------ABORT----------ABORT----------ABORT---------ABORT


rem ----------EXIT----------EXIT----------EXIT----------EXIT--------------EXIT
:exit 
findstr /v /i /c:"0 File(s)" Backuper_log.txt > Backuper_log2.txt
type Backuper_log2.txt > Backuper_log.txt
del Backuper_log2.txt
exit
这两个文件位于外部驱动器中

如果您想查看关于这个小程序开发的我的其他问题,然后回答,这些问题的顺序如下:

谢谢你的帮助很抱歉我的英语不好(我是葡萄牙人:)