-4

I have a backup up batch file that I run on several computers and laptops the file is located on different drive (letters) on each machine. So the batch file needs to determine the files location and then run it from that drive, so is there a way for one get the drive letter using the drives property name?

Regards, Paul

3 Answers3

0

Not very clear what you mean, but try this on the command line:
(if you put it in a BAT file, change %a to %%a)

for /F "delims=\" %a in ('cd') do echo %a

The result of the echo will be your current drive (frequently C:)

abelenky
  • 63,815
  • 23
  • 109
  • 159
  • Thank you. What I am trying to accomplish is this. I have a thumb drive with a backup batch routine that I run on several computers. Depending on the user and the computers configuration the thumb drives drive letter could be different. I need a way I need a way to determine the thumb drive "drive letter" based on the thumbs "name". So that I can set some environment variables with this information that way every installation will work regardless of the thumb drive drive that gets assigned when it is used. Regards, Paul – user3901114 Aug 02 '14 at 00:32
0

This will detect the last drive which has the file (add more drive letters)

@echo off
set "drv="
for %%a in (c d e f g h i j k l m n) do if exist "%%a:\" if exist "%%a:\folder\name.txt" set "drv=%%a:"
if defined drv echo the file was found on drive %drv%
foxidrive
  • 40,353
  • 10
  • 53
  • 68
  • Thank you all for your advice. It seems that if I show you what I need to accomplish it might help. It is the simple batch file I me using to back daily work. On each machine – user3901114 Aug 02 '14 at 14:55
0

I am afraid there is a misunderstanding here. If you have a Batch file that is running, then there is a very easy way that "the batch file to determine the location from where it start running":

@echo off

set myDrive=%~D0
echo I am running from: %myDrive%

If the batch file is in another location, then it first needs to start running in order to determinate the location of other files and then just change the current directory to such location. In this case, foxidrive's answer provides a solution.

Aacini
  • 65,180
  • 12
  • 72
  • 108
  • Thank you all for your advice. It might be better if I just showed you the batch I use to backup daily work. – user3901114 Aug 02 '14 at 14:59
  • set MTH=%DATE:~4,2% set DAY=%DATE:~7,2% set YR=%DATE:~10,4% set BkDte=Backups_2GB--Daily_Backup--%MTH%.%DAY%.%YR% k: cd F-All\Backups 2GB -- Daily Backup\ MD %BkDte% xcopy h: /M /s /V %BkDte% – user3901114 Aug 02 '14 at 15:00
  • I this cased I would like to replace the hard drive letters "K: and H:" with their drive names. As depending on which computer the thumb drives are put the drive letter changes but nit the drive name. – user3901114 Aug 02 '14 at 15:03
  • Thank you everybody for all advice. – user3901114 Aug 02 '14 at 15:05
  • How many USB drives are being used in this task? Do you locate a USB drive in explorer and double click the batch file? If not then how do you launch it? Do the USB drives have a set volume label? – foxidrive Aug 02 '14 at 16:30
  • There are two thumb drives. The batch file is a scheduled task and is located in a batch directory on the c drive. – user3901114 Aug 02 '14 at 17:37