use of "rmdir" command with batch file - batch-file

I don't have exact directory path rather its absolute in terms of current working directory.
whenever I am using this path, it prompts to ask wether its a directory or file, how to suppress this prompt.
rmdir "..\Sample\special" /s/q

Related

Relative path doesn't work on shared directory

xcopy "D:\CCStudio\rtos" panasonic /s /e
The folder panasonic and the bat file are on the same level in the directory structure, although on another machine I have access to.
When I use the bat script on my PC everything works fine. But when I put the bat script into the remote shared folder, it doesn't work as expected. The problem seems not to be the source, instead the destination address is the key in the problem. When I replace `pansonic' whit its absolute address, the script works.
So why should I specify absolute path for destination? Recall that the destination is external path. It is shared folder on another windows machine.
I currently run a bat from a shared drive to copy to another shared drive. This is what I use to get it working fine. Adjust as needed.
cd /d %~dp0
xcopy /s "D:\CCStudio\rtos" "panasonic\" /E
cd /d %~dp0 will change the directory to what ever the batch file is in allowing you to use relative paths. This script will copy the files in rtos to panasonic. Folder path will look something like this X:\Shared\Network\panasonic\RtosFiles.ini assuming RtosFiles.ini was in D:\CCStudio\rtos and the batch was run in X:\Shared\Network\

Relative network path in a .bat file

I need to run a .bat file in a network path (UNC path).
At the beginning, my bat file was something like this
cd subfolder
some file operations
When I tested it on my local computer, it worked, but when I move the file to a network directory, I have:
'\\ComputerName\SharedFolder\Resource' is an invalid current directory path. UNC paths are not supported.
Defaulting to Windows directory.
C:\Windows
I tried to use pushd command, but it didn't help:
pushd subfolder
some file operations
 
'\\ComputerName\SharedFolder\Resource' is an invalid current directory path. UNC paths are not supported.
Defaulting to Windows directory.
C:\Windows>pushd subfolder
No such directory.
I can of course write something like this
pushd \\ComputerName\SharedFolder\Resource\subfolder
but I want to use the same .bat file in several folders, so I want to use a relative path. Is it possible?
Only pushd can be used to switch to an UNC path, so first use pushd to the path of the batch file, then cd subfolder:
pushd %~dp0
cd subfolder
some file operations

batch file command line start in same folder as executable on network path

I know from a desktop I can have a bat file that runs an executable with specific parameters and starts in the same path on the network where the executable exists, but how can I accomplish the same thing when calling the bat file assuming is in same folder as executable from another application?
For example:
\My-Network\app\PR8.exe /noload
I want to start specifically in \My-Network\app (same folder where PR8.exe exists) but not where it defaults to which seems to be c:\windows somehow. I can't seem to do a cd on a UNC path and I don't want to use any path letters as the application also detects as to which server it is executing from as well.
It isn't possible to set a UNC working directory for Windows batch files without network mapping drives. However, in Windows 2000 and later, you can use the PUSHD and POPD commands to change the working directory to a UNC share when running your script.
Wikipedia gives us the example of creating a shortcut to your batch file where the Target is set to the following:
%COMSPEC% /E:ON /C "PUSHD """\\My-Network\app\""" & C:\PATH\TO\BATCHFILE.BAT & POPD"
In this case the Working directory attribute of the shortcut is ignored, as the PUSHD and POPD commands will change it to the path specified.

how do i change an elivated batch files directory to the location of the batch file

Can anyone tell me how to change an elevated batch files directory to the location of the batch file? I am trying to make a program and it won’t work unless it is elevated and it has files it needs in the save folder. Can anyone help?
I think what you are referring to is when you 'Run as Administrator' the current directory changes and you can't reference folders/files unless you use the full path. To set the curent directory to the directory of the batch file add this line near the beginning of your bat file (before your reference any folders/files).
pushd "%~dp0"

How to install inf file from base directory from Batch File (.bat)?

I want to make a Batch File (.bat) to install an .inf file that is located in the base directory of the .bat file. I managed to install the .inf, but only if I specify the full directory. How can I install the .inf file without specifying the full directory?
Here's what I have so far:
%SystemRoot%\System32\InfDefaultInstall.exe "DroidInstaller.inf"
Any help would be greatly appreciated.
Your question is quite vague. If both files (your installer.bat and the inf file) are in the same directory then you can add pushd "%~dp0" at the start of your batch-script:
#echo off
pushd "%~dp0"
%SystemRoot%\System32\InfDefaultInstall.exe "DroidInstaller.inf"
This will set the working directory to the directory where your batch-script runs in. If this directory is the same as the directory of your inf file then you are able to call the DroidInstaller.inf the way you did in your question.

Resources