Iterate using particular dll name [duplicate] - batch-file

This question already has answers here:
How to find folders and files with specific pattern
(2 answers)
Closed 6 years ago.
Is it possible to iterate a folder searching for particular dlls name using batch file? I know that *.dll iterates all the dll in specified location. But I couldn't find solution for searching for particular dlls using batch file. My dll naming structure will be like myassembly.{name}.dll. I have to search for the dlls in the name starting with myassembly.
I have tried as myassembly.*.dll. But it didn't worked.

You can use the where command:
Where folder:myassembly.*.dll
This searches your directory, named folder, for all dll's whose name begin with myassembly.
Where/R folder myassembly.*.dll
This searches your directory, named folder, and all of it's sub directories for all dll's whose name begin with myassembly.
Type where/? and hit enter in a cmd window for more information.
[Edit /]
Based on your comment, you are probably wanting something like this
For /F "Delims=" %%A In ('Where %id%:myassembly.*.dll') Do Echo=%%~fA

Related

Batch deleting exact file extensions [duplicate]

This question already has answers here:
Delete file with specific extension in batch file
(3 answers)
Closed 2 years ago.
I have .blk and .blkx files in the same folders, of wich im trying to delete only the .blk file. Ive attempted examples found on this post as in del "\folder\*.blk" /s. I managed to get the chosen files deleted however the .blkx files were deleted too (other files werent so i assume its an issue with both the file having .blk in their extension).
How can i select only the .blk file?
Edit: I dont know why this post was marked a duplicate but the above pinned post does not resolve the problem (wich i already talked about not working)
You must have SFNs (short filenames) enabled on that drive, and the .blkx extension is mapped to .blk in the short 8.3 filename. Because of this, and because wildcards match both long and short names, *.blk returns both .blk and blkx files. To distinguish between them you'll need to run a for loop, check the actual extension, and delete each .blk individually.
for %%b in (*.blk) do #(if /I "%%~xb" == ".blk" echo del "%%~b")
Remove echo from the above to actually delete the .blk files.
To recurse into subdirectories (like del /s) use for /r instead of for.
The command is written as to be used in a batch file (per the question tag). To run it at a command prompt, instead, replace the double percents %%b with single ones %b.

Uninstall software with a non constant installation directory path [duplicate]

This question already has answers here:
Batch command to copy files from source to destination [duplicate]
(1 answer)
Copy Contents From Folder Using Wildcard On The Directory
(1 answer)
xcopy wildcard source folder name to destination
(2 answers)
Using a batch file to copy files with a wildcard in the directory path?
(2 answers)
Closed 3 years ago.
I'm trying to write a batch-file to uninstall GoToMeeting.
Currently I use the following to uninstall the current version:
echo UnInstalling GoToMeeting........
"C:\Program Files (x86)\GoToMeeting\13190\G2MUninstall.exe" /uninstall -silent
The problem is, with each install of a new version, the install directory changes. For example, the version is 13190 but the previous time it was 13022 and 12771 before that. So I practically have to add a line for each version and that is really annoying.
Is there a way using a batch-file to make the directory a wild card during the uninstall?
sorry, no wildcard allowed unless in the very last element of a path or filename.
Instead use a for /d loop to list all subdirectories of a certain directory:
for /d %%D in ("C:\Program Files (x86)\GoToMeeting\*") do (
echo the file you look for is "%%D\G2MUninstall.exe"
)
Bonus: if several versions are installed, this finds all of them

How to unzip a ZIP archive file using batch file? [duplicate]

This question already has answers here:
How can I compress (/ zip ) and uncompress (/ unzip ) files and folders with batch file without using any external tools?
(6 answers)
Closed 4 years ago.
I would like to use a .bat file to unzip a ZIP compressed archive file if possible at all. Nothing fancy, I just want to extract the entire archive file to the same location, i.e. download a .zip file to desktop and want to extract it next to desktop with the same name.
I tried this, but with no success.
for /R "C:\Users\Desktop\test.zip" %%I in ("*.zip") do(
"%ProgramFiles(x86)%\7-zip\7z.exe" x - y -o"%%~dpnI" "%%~fI"
)
exit
You shouldn't need the loop. Depending on whether you want to extract the directory structure contained within the archive or just extract everything to a single directory, you would use:
7z e C:\Users\Desktop\test.zip -o C:\Users\Desktop\test
or
7z x C:\Users\Desktop\test.zip -o C:\Users\Desktop\test
See https://sevenzip.osdn.jp/chm/cmdline/commands/index.htm for a list of commands and drill down as needed for the various options.
You should not need a for loop in your batch file, unless you intend to only extract files based on a list of patterns.

How can I parse a dragged file's path in a Windows batch script? [duplicate]

This question already has answers here:
Drag and drop onto Python script in Windows Explorer
(8 answers)
Closed 5 years ago.
I have a python script that I want to be able to drag .exe files onto and have that python script process the files. I don't think Python easily supports this so I want to make a .BAT file which, for a file dragged onto it, gets the path of that file and then runs something like:
python C:\files\myPy.py [full path to dragged .exe here]
Basically, it just runs my script with the dragged file as an argument.
The part I am struggling with is simply getting the path of a dragged executable. Would this be %%f or %1?
The 0-th argument of a batch-file is the path to the batch-file itself. The 1-st argument is... Well the first thing you put after which (when dragging the file onto the command-line) that should be the path to the executable.
To make sure everything is properly enclosed in double-quotes, you now want to first remove all surrounding quotes and then add new ones:
python C:\files\myPy.py "%~1"
The ~ removed the (potentially) existing quotes. If there are none, it does not remove anything. This makes it possible to make safe that the quotes are correct (at least for further use in batch; not sure about python).

.bat file to rename and move files with prompt

I am completely new to this, but I am trying to create a .bat file that will allow me to rename a pair of files within a designated folder and move them into a subfolder. The part I am having trouble with is that I am wanting a prompt to come up to identify/select the files to be renamed and moved.
Example file names are:
A1234, A1235, A1236, B1234, B1235, B1236, etc.
Is there a way to bring up a prompt that allows the user to type the shared name (ex 1234)of the files and rename and move both files to the designated subfolder?
Any and all help would be appreciated!
Suggested approach
for part of problem
part I am having trouble with is that I am wanting a prompt to come
up to identify/select the files to be renamed and moved. Is there a
way to bring up a prompt that allows the user to type the shared name
(ex 1234)of the files and rename and move both files to the designated
subfolder?
Do a search operation using wildcard, like "?1234" for the case highlighted above ( should be made generalized for all acceptable and expected patterns "*1234*" is the generic most )
Now do a RENAME inside a For loop on the results obtained by search.
As you suggest you are a newbie with Batch, following tutorials will help you build your file. Look for elements like Variables, For Loop
Batch Tutorial
Here you go
#echo off
set /p file=Please type shared name:
for %%a in (C:\Folder\?%file%.*) do (
move "%%a" subdir
ren "subdir\%%a" newname.*
)

Resources