How to specify the current directory in Windows Shell?

半腔热情 提交于 2019-12-31 19:50:19

问题


I have the following BAT file which is intended to archive the specified folder, protect it by a password and copy the archive file to my local Dropbox folder.

    "C:\Program Files\7-Zip\7z.exe" a -mx9 archive.7z "G:\This is a test\directory\with subdirectories\" -psecret -mhe=on

    xcopy "G:\This is a test\directory\with subdirectories\archive.7z" "G:\My Documents\My Dropbox\" /c /d /s /e /k /y

I use 7-Zip for archiving.

Is it possible to alter the script in such a way that I can put it in any folder I choose and it does the same - archive the current folder, protect it by a password and copy the archive file to my local Dropbox folder?

Simply said, what is the command for "archive the current directory and any sub-directories"?


回答1:


%CD% is your current directory. Try echo %CD% in a dos prompt to try it out.




回答2:


You can specify "the current directory" simply as ., for example:

"C:\Program Files\7-Zip\7z.exe" a -mx9 archive.7z . -psecret -mhe=on
xcopy archive.7z "G:\My Documents\My Dropbox\" /c /d /s /e /k /y

It's just a more complicated case of doing something as easy as dir .




回答3:


You can get the current directory path if from the script path you put this line at the top of your script file:

$CurrentDirectory = Split-Path $MyInvocation.InvocationName


来源:https://stackoverflow.com/questions/6664580/how-to-specify-the-current-directory-in-windows-shell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!