Windows Batch Script Get Current Drive name

前端 未结 8 1781
情话喂你
情话喂你 2021-02-02 09:30

I have a batch file which is on a usb key. I need to know the drive name the batch is in.

Example, if it\'s E:\\mybatch.bat it should find E:\\ same thing for F:\\, G:\\

8条回答
  •  醉话见心
    2021-02-02 10:07

    Thanks Very Much @Sparky3489, if I have just one USB Flash Drive, I put this within your Algorithm, Right After the

    echo %%i is a USB drive.
    Set FlashDrive=%%I
    

    I also changed the Wording of the Identifier to

    Echo %%i is a USB Flash Drive~!
    

    Then, After, {and Outside} the Algorithm, I can add the Flash Drive Path such as...

    Set FlashPath=%FlashDrive%\Users\Public\Documents
    

    Then by setting up other Paths Such as

    Set SourcePath=C:\Users\Public\Documents
    

    I can make an Batch File BackUp For the Flash Drive, (can be Called Via Windows Short-Cut with an Associated Icon in your Quick Launch Window ~ Search "Quick Launch", if in Doubt to what I'm Talking About).

    Rem  * * * * * * * * * Start Batch File * * * * * * * * * *
    @Echo OFF
    cls
    Echo FlashDrive UpDater for
    Echo.
    Echo Excel, Word ...
    Echo * * * * * * * * * ~ Excel SpreadSheets ~ * * * * * * * * *
    XCopy /D /I /V /Y /U /S "%SourcePath%\Excel Documents\*.*" "%FlashPath%\Excel Documents\"
    Echo * * * * * * * * * ~ Word Documents ~ * * * * * * * * *
    XCopy /D /I /V /Y /U /S "%SourcePath%\Word Documents\*.*" "%FlashPath%\Word Documents\"
    Echo.
    Echo.
    Echo FlashDrive = %FlashDrive%
    Echo FlashPath = %FlashPath%
    Echo.
    Echo * Bonus Switch Info * * * * *
    Echo * XCopy Switch  /D ~ Copies Files Changed On or After the Specified Date.
    Echo *          {If no Date is Given, Copies only those Files whose
    Echo *          Source Time is Newer than the Destination Time}.
    Echo * XCopy Switch  /I ~ Copies More than One File to Destination (Assumes Destination is a Directory)
    Echo * XCopy Switch  /S ~ Copies Directories and Subdirectories Except Empty Ones
    Echo * XCopy Switch  /V ~ Verifies Each New File.
    Echo * XCopy Switch  /U ~ Copies only Files that Already Exist in Destination.
    Echo * XCopy Switch  /Y ~ Suppresses Prompting to Confirm You Want to Overwrite an Existing Destination File.
    Echo.
    Rem for More Info on XCopy Switches GoTo http://support.microsoft.com/kb/128756
    Echo Directory Path = %~DP0
    Echo.
    Echo * Batch File Name = %0 *
    Echo.
    Rem Echo %CD:~0,2%, {Returns "Drive Letter & Colon"}
    Rem Echo %CD:~0,3%, {Returns "Drive Letter & Colon & BackSlash"}
    Pause
    cls
    Pause
    Exit
    Rem  * * * * * * * * * End Batch File * * * * * * * * * *
    

提交回复
热议问题