Reputation: 85
I have created a batch file to zip my backups, but the batch files works only if I copy the batch file to the 7zip.exe folder on c drive; otherwise it doesn't work . How do I run my batch file from any location?
Here is my command:
7z a -mhe -p1234 -t7z "D:\Batch test\2\%datetimef%.7z" "D:\Batch test\1*.*" -mx0
Upvotes: 0
Views: 6347
Reputation: 917
You can put the full path to the 7z binary like so:
"c:\7zip"\7z a -mhe -p1234 -t7z "D:\Batch test\2\%datetimef%.7z" "D:\Batch test\1\*.*" -mx0
You're explicitly telling the interpreter where to look for the binary.
Upvotes: 0
Reputation: 57252
PATH %PATH%;"c:\7ZIP";
7z a -mhe -p1234 -t7z "D:\Batch test\2\%datetimef%.7z" "D:\Batch test\1*.*" -mx0
where the c:\7zip
is the folder where 7zip is.
The problem is that your 7z.exe
is not in your PATH variable and cannot be found and executed.While when it is in the same directory it can be found and there is no problems with your execution.For script purposes you can edit the %PATH% variable with PATH
command or edit it through environment variables .
Upvotes: 2