I have what I believe should be an easy answer to a question but I am having a difficult time figuring out the coding for it.
I have a batch file that runs when single or multiple files are sent through the SEND TO command when right clicking.
What I would like is if the file(s) are coming or located on a specific drive letter then it will go to a dialog and end.
I just need help figuring out the drive letter part...
if "file directory letter" = W: goto :errordialog
I have tried:
if %cd%=="W:\" goto :errordialog
if %~d1=="W:\" goto :errordialog
I have tried other codes but I think I have to do it another way?
I know I have to be making this too hard right?
Well what seemed to work is :
[%~d1]==[W:]
Late answer, but this is safer:
if "%~d1"=="W:"
The quotes(") makes the string as one piece. So this wouldn't happen:
if [ ]==[W:]
Although this shouldn't happen when %1 is a path, just a pre-caution.
Related
I want to start with a little disclaimer:
I read this thread on a similar issue to mine, but it seems like the solution doesn't work. It might just be me not understanding it completely but here I am asking for clarification.
My goal is to copy a shortcut to the start menu programs folder conserving all of its attributes, icon and start in value. I thought making a copy would be simple but it seems like my brain can't understand anything today.
So here's the actual xcopy argument:
#echo off
xcopy "%~dp0\file.lnk" "%userprofile%\Start Menu\Programs\file.lnk\" /p /v /f
pause
I have tried every combination of adding/removing the file name, with/without the \ at the end and any combination of both... I also tried running the batch file as administrator just in case.
The #echo off is just a habit and the pause is to allow me to read any error messages that could pop up. I also put the extra arguments into the xcopy line to try to get more information. It doesn't seem to help me a lot though.
I'm starting to think the issue is completely isolated from the other thread.
As suggested by SomethingDark, changing the path from %userprofile%\Start Menu\Programs\ to %AppData%\Microsoft\Windows\Start Menu\Programs\ fixed my issue.
Hi again this has been fixed/answered just I cant answer my own question for 8 hours
... may have stuffed up a line or two with spelling mistakes..
sorry to waste anyone's time and thank you Gary for pointing out to check the reg file.
Hi everyone this is my first day... yes first day messing around with .bat files, and I have been googling the net for ages to figure this out so any help would be great.
I have been trying to get my .bat file to run a reg file from a different location, the .bat file is on the desktop. the .reg is in a folder which is located on the desktop.
what I have wrote so far is
regedit.exe /s "C:\Users\Crash Bot V1.0\Desktop\Reg Files\ChangeOpenToOpen_With.reg"
just to add, this is being done in virtual box on a windows 7 installation.
be as harsh as you feel if it is an idiots mistake, thanks again for any help.
was my path and a spelling mistake, found a neat way to avoid this issue if you know where the item is, go to it hold left shift and right click and there is a option called copy as path then when you paste you will have the path of your selected item. hope this helps someone.
Alright so excuse my lack of knowledge, just actually started learning about coding and am trying something out with a few programs.
I have an .exe and a .bat file that I want to string together so that I have one .bat file that I run. I would rather not edit the other bat files. The problem is the .exe file l poses two questions and creates a file.mesh. Now the first question's answer is always 0 so I'm wondering if there's a way to enter the 0 outside of the exe file, and the second is the name of a file which I want to keep as user input.
In addition to that, I want to take the name that I just put in in the second question to automatically run through a second batch file which creates another file...
So essentially what I want is to have the .bat open and ask for a name of a file, then run both the exe and the other .bat. can anyone give me some direction as to where I should start researching or could help me write?
Depending on how the EXE file is written, this may or may not work. Try it and see.
>file.txt echo 0
>>file.txt echo filename.bin
exefile.exe <file.txt
or
>file.txt echo 0
>>file.txt echo filename.bin
type file.txt|exefile.exe
Simply a line in HelloWorld.bat should read:
Echo 0 ¦ foobar.exe
I have a very simple problem:
call myBatch.bat "K:\dir name with spaces\eatThis.xml"
Which will not work, it will stop with
K:\dir does not exist
Could you please point me to the SO question addressing such an issue? I've already dug myself through quite a lot of SO questions regarding batch files and whitespaces in parameters but I guess the solution to my problem must have been ignored accidentally.
--
OK, after some debugging it turned out that it was not the batch file that was faulty but the Java application that invokes String.split(" "); to separate multiple arguments from each other. So when one argument contains a space, in its path, the application logic falls apart. As the original question no more describes what the real problem is, shall I rewrite it completely or write a new one? Anyway, my bad, feel free to downvote is.
I created the following mybatch.bat and started it with call myBatch.bat "K:\dir name with spaces\eatThis.xml" Output is:
"K:\dir name with spaces\eatThis.xml"
Mybatch.bat:
echo off&setlocal
echo "%~1"
Hi I want to stop a batch file if it is being run from a particular drive. I have tried somehting like this, it doesn't work though. I would appreciate it if someone has a better idea.
if %CD%=="^.*C:\" (goto :CDrive)
Where :CDrive is an error message saying that the user is trying to run it from the wrong drive.
Cheers
Chris
You can use a substring to check:
if "%CD:~0,2%"=="C:" goto CDrive
Another option might be that you just explicitly set the drive you're expecting:
pushd X:
or use full paths instead of relative ones.