简体   繁体   中英

Closing multiple batch files

First time poster so hope I get this right.

I am trying to set up a batch file that first reads in the current date and time and makes a folder from it as below:

@echo off
SET dirname="%date:~0,2%-%date:~3,2%-%date:~6,4%-%time:~0,2%%time:~3,2%"
mkdir Bat\%dirname%
attrib +s +h %dirname% /s /d

Following this I pull some backups in to the folder and then want to zip it with 7zip command line and have added this line to the first batch file:

start /wait Bat\7Zip.bat %dirname% Bat\%dirname%* -r

which calls 7zip.bat which is here:

@echo off
Bat\7z.exe a -mhe -p*** Bat\%dirname%.7z Bat\%dirname%* -r
exit 0

finally I try to delete the original folder using:

start /wait del /F /Q /a Bat\%dirname%
exit 0

Here are my two problems. First off, when it runs the 7zip file, after it completes, the second command prompt stays open, when I close this manually the first prompt asks if I want to abort the batch job even though its finished. I would like it all to just close on its own.

Second off. The del command works in so far as it deletes the files in the folder but not the folder itself, any ideas what I am missing?

Thanks in advance for all the help. Sorry this is one of my first batch attempts so is probably very sloppy.

@echo off
SET "dirname=%date:~0,2%-%date:~3,2%-%date:~6,4%-%time:~0,2%%time:~3,2%"
mkdir "Bat\%dirname%"
Bat\7z.exe a -mhe -p*** "Bat\%dirname%.7z" "Bat\%dirname%*" -r
RD /S /Q "Bat\%dirname%"
exit 0

关于目录del /F /Q /a Bat\\%dirname%第二个问题的答案:在del /F /Q /a Bat\\%dirname%您必须致电rmdir Bat\\%dirname%

from start /help

command/program If it is an internal cmd command or a batch file then the command processor is run with the /K switch to cmd.exe. This means that the window will remain after the command has been run.

  If it is not an internal cmd command or batch file then it is a program and will run as either a windowed application or a console application. 

so you should use start /wait Bat\\7z.exe [...] instead of start /wait Bat\\7Zip.bat [...]

regarding the dir removal use RD /S /Q [drive:]path (use with caution)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM