|
Answer» hey guys new here, i wanted to pick your brains as im struggling to find an answer to what im looking for!
basically IVE got some software that my dad had wrote by a programmer it ships with hardware he sells, (vehicle diagnostics etc) im editting his installer that runs from a usb key which also acts as a security dongle so it has to be by dongle and i cant SWITCH to CD or DVD , it uses a batch file which i will eventually convert into a .exe as long as the code all works
the batch file works great, it all installs fine and goes thru spot on, the only thing i cant get to grips with is i would like to delete some driver files from the usb once it has installed, this is so people who try to steal the software will be missing crucial drivers (long story but go with me on this one for now!) my problem is when you put in a usb key, its normally a different drive letter everytime, so i cant link to a static drive letter to delete from ie; C:/ D:/ etc etc, ive tried using CD\ (to go to top directory) and then DEL for delete but i cant seem to get it to work, im not overly experienced with ms dos, but ive coded in other languages so i understand the fundamentals just not the syntax,
heres what i have:
ECHO Y CD\ del folder/file1.dll del folder/file2.dll del folder/file3.dll del folder/file4.dll
i know its probably rubbish but hey ive tried for days on this before asking for help! thanks
SteveDo you care how long it is? If not, you could set up a bunch of if statements to search for a specific file on the drive then set the drive. A lot of this:
Code: [Select]if exist a:\folder\file1.dll set drv=a if exist b:\folder\file1.dll set drv=b etc...
Then you can do
Code: [Select]del %drv%\folder\file1.dll etc.
Hope this helps. Let us know if not. The OP had posted the same question in the Batch Programs Thread and I already answered it more fully, but in essence:
In a batch script %~d0 will expand to the drive letter of the drive that the script is on, so %~d0:\ is the root directory of that drive. You know the rest of the path to the files you want to delete so your commands will be something like this
Code: [Select]del "%~d0:\folder\file1.dll" The quotes aren't essential if the whole path + filename does not contain any spaces but they don't do any harm. By the way the character after the percent sign is a ZERO.
Quote from: Salmon Trout on December 01, 2011, 01:21:26 PM The OP had posted the same question in the Batch Programs Thread and I already answered it more fully, but in essence:
In a batch script %~d0 will expand to the drive letter of the drive that the script is on, so %~d0:\ is the root directory of that drive. You know the rest of the path to the files you want to delete so your commands will be something like this
Code: [Select]del "%~d0:\folder\file1.dll" The quotes aren't essential if the whole path + filename does not contain any spaces but they don't do any harm. By the way the character after the percent sign is a ZERO.
that is what i was looking for thank you! instead of naming a drive i wanted to state THIS drive whatever letter it is it dont matter just this drive! rather than actually naming a drive! ill test it and see how it works thanks hopefully i wont bug no one anymore! ill defo stick around as its quite an interesting language im just completely unfamiliar with it
do i still use CD\ or is that now redundant as %~d effectively does the same thing?
thanks!
Quote from: ekto on December 01, 2011, 01:28:11 PMdo i still use CD\ or is that now redundant as %~d effectively does the same thing?
CD\ will be redundant if you use the full path and filename. that didnt seem to work? it gives this message: the filename, directory name, or volume label syntax is incorrect
it was all running from the usb key as well?
heres my code:
ECHO Y
del %~d0:\folder\file1.dll del %~d0:\folder\file2.dll del %~d0:\folder\file3.dll del %~d0:\folder\file4.dll
pausewhat happens if you replace
del
with
echo del
? it ECHOS on screen like this:
F::\folder\file1.dll etc etc etc
is it meant to have a double colon?
thanks i tested with a single colon, i left it like this: del %~d0\folder\file.dll
but nothing happened and no files deleted, the only code i found that does work is this but it deletes the whole drive:
ECHO Y CD .. START CMD /C RMDIR /S /Q "%~dp0"
Quote from: ekto on December 01, 2011, 02:44:30 PM is it meant to have a double colon?
You spotted the problem. I made a mistake before, for which I apologise. The fact is that %~d0 becomes the drive letter and colon.
So the script should look like this
Code: [Select]del %~d0\folder\file1.dll del %~d0\folder\file2.dll del %~d0\folder\file3.dll del %~d0\folder\file4.dll
Please forgive my error.
Quote from: Salmon Trout on December 01, 2011, 03:39:32 PMSo the script should look like this
Code: [Select]del %~d0\folder\file1.dll del %~d0\folder\file2.dll del %~d0\folder\file3.dll del %~d0\folder\file4.dll
If that still isn't working, try putting quotes around it.
Code: [Select]del "%~d0\folder\file1.dll" del "%~d0\folder\file2.dll" del "%~d0\folder\file3.dll" del "%~d0\folder\file4.dll"
Quote\folder\file1.dll
We are presuming that this and the others are the actual folder and file names that need to be deleted? (I.e. they weren't just examples for discussion PURPOSES)
|