Hurtcake Posted September 20, 2007 Posted September 20, 2007 Im writing some batch scrips to make my life easier. I have the scripts on a usb-key, and i want them to work even if i move them around, to lets say the desktop. Untill now im been using example: .downloadsccleaner.exe to run the files. But that won't work if i move them. My question is, is it possible to make a path using the name of the HD or the usb-key instead of x:downloadsccleaner.exe (cause the letter may change from time to time) If that made some sense :P Or does anyone else have some better ideas or tips? :) Quote
Sparda Posted September 20, 2007 Posted September 20, 2007 use relative paths as opposed to absolute paths. Quote
Hurtcake Posted September 21, 2007 Author Posted September 21, 2007 Can you give me an example? Not sure i understood you completly :P Quote
digip Posted September 21, 2007 Posted September 21, 2007 It will only work if the bat script is in the root of the folder where the rest of the files are. So if you want it to run it from "./bat files/downloads/ccleaner.exe" then make sure the bat script is in a folde, let's say "bat files" and then the downloadsccleaner.exe is within that "bat files" folder. Then whenever you move the "bat files" folder any of the bat files you click on will still run, even when copied from the flash drive to the hard drive. Quote
Hurtcake Posted September 21, 2007 Author Posted September 21, 2007 It will only work if the bat script is in the root of the folder where the rest of the files are. So if you want it to run it from "./bat files/downloads/ccleaner.exe" then make sure the bat script is in a folde, let's say "bat files" and then the downloadsccleaner.exe is within that "bat files" folder. Then whenever you move the "bat files" folder any of the bat files you click on will still run, even when copied from the flash drive to the hard drive. You're talking about moving the whole folder around, right? I wanted to keep the files on the usb-drive, and just have the batch file on my desktop. Without using the usb-drive letter. Anyway I played around some more, and i found a solution that worked for me @echo off :: variables if exist "d:systemscripts" set drive=d: if exist "e:systemscripts" set drive=e: if exist "f:systemscripts" set drive=f: if exist "g:systemscripts" set drive=g: if exist "h:systemscripts" set drive=h: if exist "i:systemscripts" set drive=i: if exist "j:systemscripts" set drive=j: if exist "k:systemscripts" set drive=k: start %drive%systemccleanerccleaner.exe exit Then the batch wil automatic assign the right drive letter, and i dont have to worry about the drive letter if the computer decide to change it. :) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.