bat file - delete directory contents except specific file and specific subfolder - batch-file

I have a directory 'help' where a web application is deployed. It contains a number of files at the root level and a number of sub folders.
I'd like to run a bat file (from outside the directory) which deletes everything within the directory except for the web.config file and a folder called 'log'.
Is this possible?

Not directly, but what you can do is copy the file and folder in a different location, delete the entire content of the folder, then restore the file and folder.

Related

How to delete specific folder files from gitlab repository using bat

I want to delete all files in specific folder from Gitlab using a batch file.
My Git repository folder looks like:
Branch :Develop
Test_Repo\Files\MyFiles\F1,F2,F3,F4,F5.....
Before cloning, I need to delete all files from under MyFiles directory
How to handle this in a batch file, I am stuck in this part?

XCOPY files from directory with Batch file

In a folder I have a batch file and another folder name Themes.
I would like to be able to share this with others so looking to make the source directory independent of the location of the parent.
XCOPY /E/Y "\Themes\*.thmx" "C:\Users\%username%\AppData\Roaming\Microsoft\Templates\Document Themes\"
Running the batch file returns "File not found - *.thmx"

Context Menu on folder opens in a parent directory

I created a batch file that edits filenames in specific folders.
I would like to add a context menu to it to make it easier to use.
So here is my reg file
[HKEY_CLASSES_ROOT\Folder\shell\Rename Here]
[HKEY_CLASSES_ROOT\Folder\shell\Rename Here\Command]
#="\"C:\\Rename\\rename.bat\""
The problem is that when you right click on a folder the command opens in the parent directory so it renames the parent directory's files.
When i run the bat file manually in any given folder it works fine.
Any help?

Executing the .msi from batch file in same location

We need to run a .msi file from batch file which is working fine if the path of .msi file is hard coded in batch file. Is there any way to get the path of .msi file dynamically as the batch file and .msi file exist at same folder location? It will really solve the purpose as thses needs to be copied to multiple servers...
%~dp0install.msi
%~dp0 gives you the path of your bat-file.
(note, that the last backslash is already included.
try #echo %~dp0 in your batch-file)
If the batch file and msi file are in the same folder then no path at all is needed. The batch file defaults to the current directory - and will write the log file to the current directory.
This is only an issue if the batch file is launched from a network drive.

How to create a batch file from root folder to install bat files in sub folders

I have three sub folders, each contain different packages and that three packages will install through three different batch files which are present inside of the each folder.Now i need to create a batch file from root folder to install these three batch files.
Put the following in a batch file in the root folder, changing the folders and batch files to your folder and files names:
call Folder1/install1.bat
call Folder2/install2.bat
call Folder3/install3.bat

Resources