How to specify the current directory in Windows Shell?

前端 未结 3 1231
栀梦
栀梦 2021-02-05 10:39

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.

          


        
相关标签:
3条回答
  • 2021-02-05 11:19

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

    0 讨论(0)
  • 2021-02-05 11:21

    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 .

    0 讨论(0)
  • 2021-02-05 11:36

    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
    
    0 讨论(0)
提交回复
热议问题