batch file to search folder for dll file names - batch-file

I need to write a batch file that will search a folder for all dll's, take their name do some processing with such. So for example a folder containing
File1.dll
File2.dll
File3.dll
within C:\temp
should return
File1
File2
File3
I would like to do some further processing then with these filenames.
Any idea how I might do such?

for /r %i in (*.dll) do #echo %~ni

Related

batch find file, replace with another file, that is supplied

I need help creating a batch file to find multiple files named the same thing in 100's of files and replace the with a different file...
Alternatively, is there a program that will do this if I select the 2 different files that will search and replace them...
Find file from computer Pairing = High School DxD - Kuroka.png
Replace file with Pairing = High School DxD - Kuroka (F).jpg
Since you never provided the basic information such as What directory you wish to start a search from or You wish to convert or just rename, I will assume you wish to search your photo's folder (Including sub-directories) and simply rename file.jpg to file.png.
To search photo's and all its directories we can use the FOR /R to search for all .jpg files and DO to address the action. The script bellow will do the following.
Search and replace all .jpg extensions to .png in the photo folder directory
Batch Script:
#ECHO ON
#CD C:\Users\%username%\Pictures
For /r %%A In (*.jpg *.jpeg) Do ren "%%A" "*.png"
goto :eof

Batch Script to Rename Files to "Raw.txt" in Subfolders

Say I have a set of Subfolders, in which I have some files in them (the name of the files does not matter, nor does the file extension). How would I write a batch script to iterate over these subfolders so that I can rename all the files in them to "raw.txt". I have no idea how to approach this, I am only familiar with the "ren" command
With this command you can iterate recursively over all the files from a give directory:
for /r <rootdir> %i in (*) do #ren "%i" raw.txt
Be aware that if there is more than one file in a folder ren will not change the file's name to raw.txt. Hope it helps.

batch file: tree /f is only listing current directory

I wrote a batch file tree.bat with following code:
set output_loc=Z:
set loc=Z:
chdir /d %loc% & tree /f > "%output_loc%\tree.txt"
Let say the drive Z: has following tree
foo1
file1
file3
file3
foo2
file1
file2
tree.bat
foo1
file1
file2
file3
When I run tree.bat I get the following output in Z:\tree.txt
Folder PATH listing for volume storage1
Volume serial number is C508-09ED
Z:.
file1
file2
tree.bat
No subfolders exist
How do I get the whole tree?
Do not name a batch file like any internal or external command! Otherwise, the command interpreter gets confused, like in your case.
The tree command (file name tree.com) you are using is searched in the current directory first, and if not found, it is searched in the directories given by the environment variable PATH. The executable file extensions are taken from environment variable PATHEXT. This all means that the batch file unintentionally tree.bat tries to rerun itself.
In addition, follow MC ND's comment and replace Z: by Z:\ to specify the root directory of drive Z:, as Z: specifies the current directory of the drive, which seems to be Z:\foo2 according to your example (which is the directory containing the batch file).

Batch file to upload each numbered file to a different FTP folder

I need to write a batch file that uploads two files via FTP to different folders.
Example: filename_0001.txt copy to folder1 on server1 filename_0002 copy to folder2 on server1.
The names of target files are fixed.
My current batch file uploads only the first file that has the lower number -the only difference in the filenames are the numbers, that are changed daily.
user name >>script.txt
%1 >>script.txt (password as parameter to batch file)
put filename_????.txt folder1
ftp -s:script.txt [server name]
How can the other file with higher number be uploaded? I thought of checking the file names and then put them in the script. Can anyone tell any command to do that?
I need something like this:
put filename_????+1.txt folder2
Prepare a text file (folders.txt) with a sorted list of folders to use, like:
folderA
folderB
folderC
folderD
From a batch file save a sorted list of files to upload to another file (files.txt). Merge the two files together as described in question Combining multiple text files into one.
The code would be like:
#echo off
dir /ON /B filename_????.txt > files.txt
setlocal EnableDelayedExpansion
3< folders.txt (for /F "delims=" %%a in (files.txt) do (
set /P FOLDER=<&3
echo put %%a !FOLDER!
))
The output will be like:
put filename_4100.txt folderA
put filename_4101.txt folderB
put filename_4102.txt folderC
put filename_4103.txt folderD
It won't work when number of digits in filenames is different, as filename_10000.txt will be sorted before filename_9999.txt. For possible improvement, see Naturally Sort Files in Batch

Create batch file to unzip files in multiple folders

I am trying to create a batch file that searches a folder for zipped files, and unzip them. I want the script to search through all the subfolders in the main folder, and unzip everything it finds. It might be a main folder with several subfolders. Some of the subfolders will contain zipped files, but some will not.
The zipped files will look like "filename.r00", "filename.r01", "filename.r02", and so on. One file will have the name "filename.rar", and it is this file that will need to extracted using 7-zip.
Is it possible to write a batch file that does this, and then deletes all the zip files? I have already installed 7-zip, so if it is possible I would like to use it. If anyone could help me write the batch file, it would be much appreciated!
Thanks!
Here you go
for /r C:\Mainfolder %%a in (filename.r*) do (
7z e %%a -o%%a_Extracted
del %%a /f /q
)
After looking at the switches for 7-Zip this might be faster (untested)
7z x filename.r* -o*_Extracted -r
del filename.r* /f /q
Either way they are extracted to a folder with _Extracted at the end, otherwise it will extract them to a folder with the same name as the archive, and when it deletes the files, it may try and delete the folders too.

Resources