Script to delete duplicate files with same names but different extensions [closed] - batch-file

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am using Audacity's Chains scripting function to batch-convert and edit many large, uncompressed .WAV files at once to a much smaller .OGG format. I end up with a folder structure like the following:
f:/sound-recordings:
-- rec1.wav
-- rec2.wav
-- rec3.wav
-- rec4.wav
-- rec5.wav
f:/sound-recordings/cleaned:
-- rec1.ogg
-- rec2.ogg
-- rec3.ogg
Some of the source .WAV files are corrupted (note rec4.wav and rec5.wav in above example), and Audacity will not convert them (at least through the chains function). This creates a problem, as it can become very tedious to compare the two folders, and delete only the .WAV files which were successfully converted to .OGG.
In the example above, "rec1.wav", "rec2.wav", and "rec3.wav" should be deleted, while "rec4.wav" and "rec5.wav" are untouched, since they weren't converted.
I need a script (batch or python preferred) to delete any .WAV files from the main folder, that have identically named .OGG files located in the "cleaned" folder, leaving other .WAV files untouched.

#echo off
for %%I in (f:\sound-recordings\*.wav) do (
if exist f:\sound-recordings\cleaned\%%~nI.ogg del %%I
)

You can create a list of the elements in the clean directory, using split to strip off the extension and then iterator through the dirty directory checking if it is in clean.
Basic python pseudo-code would look like:
clean = [filename.split('.')[0] for filename in clean_directory]
delete = [filename for filename in dirty_directory if filename.split('.')[0] in clean]
for filename in delete:
os.remove(filename)

Related

Batch - Trying to read a text file [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm trying to make a batch file that will read a text file (Net.txt) to pull a datapath from it. Assign it to a variable then empty a file from a nearby location.
Net.txt looks like
SharedPath=C:\Program\2017\
SharedUNC=C:\Program\2017\
Then find the directory and delete files with a specific extension.
cd %variable%\OPTION\trash
DEL *.xxx
This works great locally when everything is on C: but I don't think batch/cmd supports UNC paths. Is there a better language to use?
To read a file line by line, use a for /f loop.
The following code assumes net.txt to be exactly as shown in your question and will delete the files in both the SharedPath and the SharedUNC (should they differ; if they are the same, del will spit an error for the second one (which you can suppress with 2>nul))
for /f "tokens=2 delims==" %%a in (net.txt) do del "%%aOPTION\trash\*.xxx"
If that is not what you want, please describe your problem in more detail.

Moving file using cmd? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have a file that I have downloaded from Google (it is inside the download folder)
and I want to move it to the autorun folder ( The folder where files run when the computer turns on).
I need to move the file using a cmd command ( the reason why is that it's going to be done using the USB rubber ducky.
I am using windows 10 64 bit if it is any help.
The path where the file is
C:\Users\%USERPROFILE%\Downloads\Test.exe
and the path I want to move it to is
C:\Users\%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
The reason why %USERPROFILE% is that it should work on all computer.
To move a file, you use the move command.
move "%USERPROFILE%\Downloads\Test.exe" "%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
I put quotes around the source and target in case you're one of those people who has spaces in their username for some reason (and the target needs them anyway for the spaces in "Start Menu").
From the output of move /?:
Moves files and renames files and directories.
To move one or more files:
MOVE [/Y | /-Y] [drive:][path]filename1[,...] destination
[drive:][path]filename1 Specifies the location and name of the file
or files you want to move.
destination Specifies the new location of the file. Destination
can consist of a drive letter and colon, a
directory name, or a combination. If you are moving
only one file, you can also include a filename if
you want to rename the file when you move it.
[drive:][path]dirname1 Specifies the directory you want to rename.
dirname2 Specifies the new name of the directory.
/Y Suppresses prompting to confirm you want to
overwrite an existing destination file.
/-Y Causes prompting to confirm you want to overwrite
an existing destination file.
To move file use mv, but not working if you don't do with admin, how you can hack, try superuser tools for windows!

Extract zip contents into directory with same name as zip file, retain directory structure [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I would like to write a bat script to do the following:
Use 7 Zip to extract files from an existing zip file, into a folder by the same name as the original zip file (bar the .zip extension), and keeping the file & directory structure that was contained in the zip file.
I can extract all the same files into the current directory, by using
"C:\Program Files (x86)\7-Zip\7z.exe" e myZipFile.zip
Reading the help of the 7z-command by just typing "C:\Path To\7-Zip\7z.exe" gets the help with all possible arguments. Here we find the following interesting ones:
e : Extract files from archive (without using directory names)
and
x : eXtract files with full paths
Trial and error shows that the latter is the one fitting your desired behaviour without bigger effort :)
After the comment by #BadmintonCat here is the addition that will create a folder to zip everything into (use as batch script with the file as argument):
#echo off
SET "filename=%~1"
SET dirName=%filename:~0,-4%
7z x -o"%dirName%" "%filename%"
From the help: -o{Directory} : set Output directory. 7z will create the directory if it does not already exist.
Just use the command: 7z x *.zip -o\*

Open a file with a batch script and manipulate it [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am working on a big project. When a user double clicks on a file with a certain file extension it opens it with a batch and checks the file for certain keywords.
I am not asking for people to type up the code for me. I just want to know how to set a default program for a file to a batch script and then have that batch script do something with the contents of the file. How do I do this?
Depending on your windows version you should be able to:
Right click the file
Choose open with
Choose choose another app
Choose More Apps
Scroll to the bottom and Look for another app on this pc.
Select your file.
To do it via the command line (you'll need an elevated one).
ASSOC .ttt=TTTHandler
FTYPE TTTHandler=c:\temp\openttt2.bat "%1"
This will associate the batch file c:\temp\openttt2.bat with the .ttt extension.
Contents of my openttt2.bat test file:
echo Hello from ttt file opener. File passed = %1
pause

To write a .bat file which will search for a string and update the old string with new one [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to search and replace string of the format IND A***B***C*** (where * in a number between0 to 9) in a file with some known string like IND A000B103C123
there are many files in which string is present.And I have to update the same string is all files eg."IND A110B123C112" .here 'IND' and 'A' 'B' 'C' is always same in both old and new version string
I want to writ a script (batch file) so that when run the batch file and give the new string as input, it will replace the old string with the new one
You may do that in a very simple way using my FindRepl.bat program:
< theFile.txt FindRepl "A\d\d\dB\d\d\dC\d\d\d" "A110B123C112"
In previous regular expression the \d specify "any digit". FindRepl.bat is an hybrid Batch-JScript program that performs this type of find-replacements tasks (and many more) in a very efficient way. The JScript language comes pre-installed in any Windows version from XP on. You may download FindRepl.bat program from this site and place it in the same folder of your Batch solution or, better yet, in a folder of PATH variable, so you may use FindRepl in any other similar problem.

Resources