Reputation: 11
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.
Upvotes: 1
Views: 401
Reputation: 37569
@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
Upvotes: 1
Reputation: 20126
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)
Upvotes: 0
Reputation: 4689
Answer on second question about directory removement:
after del /F /Q /a Bat\%dirname%
you have to call rmdir Bat\%dirname%
Upvotes: 0