Create a batch file that will zip two files with the same name (but different extensions) - batch-file

I'm very new to programming and I recently started working at a data archive facility. A large part of my job is zipping pdf and AutoCAD files (.dwg) together. My manager has me doing this by hand and there are thousands of files to zip, so I am looking for a more efficient way.
At the moment, I have a folder that contains about 500 files, 250 of them are PDFs and 250 of them are drawings. Each pdf has a matching drawing with the same name and I want to zip them together in pairs. (The zip file should have the same name.)
The naming convention is like this:
1.pdf
1.dwg
2.pdf
2.dwg
...etc.
I want to create something like this:
1.zip (containing 1.pdf and 1.dwg)
2.zip (containing 2.pdf and 2.dwg)
I have done some research already and I understand that many people have written similar programs using batch files. However, I find myself stuck. I do not have permission to download 7zip or anything that doesn't come with Windows 7.
I tried something like this:
#ECHO OFF
PATH=K:\FOD-FDC\TSG\HOLDING\ROTATE\OSU-090344\Vol_4_complete
FOR %F IN (*.dwg) DO 7Z a "%~nF.zip" "%~nF.dwg" "%~nF.pdf"
Obviously it's not right for a lot of reasons (most notably I don't have 7-zip) but I am still trying to find a solution.
Can anyone help me out? Thank you so much in advance!

You have to double the % in a .Batfile :
Try like this
#ECHO OFF
set $PATH="K:\FOD-FDC\TSG\HOLDING\ROTATE\OSU-090344\Vol_4_complete\"
pushd %$path%
FOR %%F IN (*.dwg) DO 7Z a "%%~nF.zip" "%%~nF.dwg" "%%~nF.pdf"
popd
Echo Done !!!

Related

Batch script to zip a folder using InfoZip

i'm a near complete beginner to batch scripting.
I'm currently learning how to create batch files. My goal is to compress a folder using exclusively InfoZip, add the date to the file name, and have that file copied to an USB memory stick plugged on H:\
The reason why i need to use InfoZip, even though it is a very old program, is because i need somthing that works even on Win95.
InfoZip is not installed, it is just unpacked in folder and ready to use.
It is possible to download InfoZip 3.0 from here:
https://sourceforge.net/projects/infozip/
Anyway, so far, the only thing i could come up with is this...
--------------------------------------
Title : Your folder will be zipped into an archive that will be copied on the USB memory stick plugged on your computer. Please DO NOT remove the memory stick during the operation.
#ECHO OFF
call d:\infozip\wiz.exe
pause
--------------------------------------
It just brings up the InfoZip window on the screen, but then i have absolutely no idea about how to make it zip a folder, add the date, and copy that zipped file to the USB.
All the regular commands meant for 7-zip or Winzip don't seem to work with InfoZip.
I could really use some help, please :)
Thanks!
Using the waybackmachine I was able to get the documentation for info-zip:
https://web.archive.org/web/20170829173722/http://www.info-zip.org/mans/zip.html#EXAMPLES
In contrary to what zip.exe shows, the syntax for zipping files is this:
zip -r zipfilename zipfilecontents
Example:
zip -r myzip.zip c:\myfolder\*.*
The -r parameter includes subfolders as well.
Problem is that the complete folder structure is included in the zip. I have not found a solution for this yet.
To solve the structure folder problem, add a cd command that will target the folder container which has inside your file or files. This before running the code proposed by Martien de Jong upside.
for example:
The path of my file is: cd C:\aa\B\file.txt
So the path you will put in the cd to target the folder container is: cd C:\aa\B
cd C:\aa\B
zip -r myzip.zip B\*.*
*Remember that this code will zip all the files included in B folder.

Batch file to move a number of files, then replace each of them with one file of another type while letting them keep their original name

First off I want to say that
-I didnt ever create a batch file yet, but I am really willing to learn
-I am not even sure if what i want to do is possible with a batch file
What i want to do is the following:
I want to replace a number of files of one file type in a folder each with one and the same file of another file type. In doing this, i want the "replaced" files to keep their original name except for the "replacer" file's extension. I am not talking about file conversion, this is about replacing several different files each with one and the same file, so each of them will look the same later, just with different names and the file extension of the "replacer" file. All of the files inside the folder are to be treated this way, there are no exceptions.
So it looks something like this:
Folder 1 Folder 2
10000000.tga------------->10000000.png (looks like replacer.png)
10000001.tga------------->10000001.png (looks like replacer.png)
10000011.tga------------->10000011.png (looks like replacer.png)
I really hope that my description is sufficiently precise, if not so, I am of course willing to give any information needed. I found parts of what i need (e.g. a loop for files in a folder, an order to replace one file with another file) but I am unsure of how to combine them at all, let alone to achieve what I actually wanted to do.
Any help is greatly appreciated :)
for %%i in (*.tga) do (
copy "replacer.png" "%%~ni.png"
del "%%i"
)
see for /? for details about the %%~.. syntax

How to copy files from a txt file to a directory

I really hope you can help me. I have a list with ROMs that I can run in coinops (old Xbox emulator). Its a text file. And I have a file with more than 10000 ROMs in it. I am looking for a batch command that can copy the ROMs that listed in the text file. Here is some info.
Place where the ROMs are:
F:\roms\
Place where the text file is:
F:\coinops\
Name of the text file:
Coinopslist.txt
Place where the roms need to go:
F:\coinops\roms\
It would be so awesome if someone can help me!
I'm not going to make your batch for you but here is an example of how you can
C:\Users\Gebruiker>echo log.txt > files_to_copy.txt
C:\Users\Gebruiker>for /F %a in (files_to_copy.txt) do copy "%a" c:\Temp\
C:\Users\Gebruiker>copy "log.txt" c:\Temp\
1 bestand(en) gekopieerd.
For anything more fancy I suggest you learn a scripting language like Ruby, it's easy to learn and fun using.

How to move all mp3 files into a single directory?

I have a bunch of MP3 files split up into artist\album, and I want to move these all into a single directory, and get rid of the directory itself, using a windows batch file (hence the tags)
You can start from:
for /R %%x in (*.mp3) do move "%%x" "c:\dir"
Use the Windows search function to search for *.MP3, wait for it to finish. Select all results and use cut. Paste into the target directory.
Then the subdirectories should be empty. You can select them all at once and delete them.
For a bit of an overkill of an effort, install any Unix utilities (e.g. CYGWIN, many oithers) and do "mv //* final_dir" :)
Of course, you will be left with a highly useful and uber cool set of unix utilities for Windows.
Another overkill is t install ActivePErl and do it in Perl:
map { move($_, $final_dir) || die "Can not move $_: $!" } glob("basedir/*/*/*");
fs-dependent, filenumberlimit experimental result was you can have thousands of files same level here, didn't try > 10000, > 1000 ok
EDIT I see you want to do wit with "win batch" (in one of your comments added later)... I leave my answer up as an alternative...
I've used JP soft's 4NT (a command.com replacement) to do this.
cd <root of mp3 tree>
global /i move *.mpr \newdir
just beware that newdir aboslutely must not be a child of <root of mp3 tree>
global executes a command (the move command) in every subdirecotry of the starting directory. /i tells it to ignore returncodes (a directory might contain zero mp3 files).
4NT is nolonger sold but "Take Command" should work also.
artist>move *.mp3 destinationDirectory will work I believe.
This should be moved to superuser, first off. Second, I use MusicBrainz for my mp3 library.
Since the question has gotten more complex, let me elaborate on MusicBrainz.
You point it at a music folder, deep as you want, and it grabs all songs found in that directory. It then offers to retag them based on it's user-generated DB. It uses some crazy method of audio finger printing to guess any songs that either lack meta-data or need the right meta-data (say goodbye to Aretha Franklin doing "Son of Preacher Man" and the famous Rolling Stones cover of "Brown Eyed Girl").
After finishing up with any meta data correction, you hit save, and it will:
a) replace/add the meta data tags
b) move your mp3 files into directories based on any pattern you specify
c) if you set this, it will delete any folders that it leaves empty upon file relocation
So, you could simply tell it NOT to retag and NOT to use any meta data for folder destination, and it will all that you want (and more if you want it to).
I have mine set to grab stuff from my "Giant Music Mess" folder and then put them into folders based on artist, album, disc, and finally give the mp3 file a "track# - title" rename. Something like Music Library/%Artist%/%Album%/%Vol%/%#% - %title

XCOPY exclude list ignored after first exclusion

I have a batch file I've created which uses xcopy to copy a dir, and child dirs, and merge them into one file. (ie. all my modulised development css stylesheets merged into one production stylesheet).
Everything is good, apart from the fact that when I reference the excludelist.txt, it only excludes the first line, and not the subsequent files I want excluded.
Anyone fancy a crack at this? You'd be most helpful.
Here's the code:
XCOPY C:\xampp\htdocs\PROJECT\css\*.* C:\temp /S /I /Y /EXCLUDE:C:\xampp\htdocs\PROJECT\exclude.txt
...and inside my exclude.txt is...
1.css
2.css
3.css
4.css
5.css
///// I know the code works (to an extent) because it is infact excluding file 1.css -- just not the ones below it. Am I right to put each exclusion on a new line?
I use the following,
xcopy "C:\users\dad\*.*" dad /s /d <yesnoyesno /EXCLUDE:excluexclu 1>cop.txt 2>err.txt
as somewhere on the web I saw a note to the effect that the /Y switch could not be used directly with an exclude file.
What I wanted to point out here, was the useful output files 1 & 2, which detail the success & failure issues.
Mine shows only success.
The short answer: Create a new text file, type the entries and save the file.
The longer explanation: I ran into this very issue on a Windows 2008 server today. I tried all kinds of things to get it to work. Forced notepad to save the file as ANSI, Unicode and UTF-8 but all of them had the same problem. Finally I started thinking about the fact that I put the file on the server via FTP and it's quite likely that FTP tweaked the file format. I created a new text file on the server, typed all the same entries in the new file and now it works.
I had a similar problem. I was trying to exclude all files with a certain extension in the root folder and any sub-folders and it didn't work. The reason was I was putting *.pdb instead of just .pdb. The newline/carriage return thing was a total red herring for me.
So my file just looked like:
.pdb
.obj
.vb
.cs
You seem to be using xcopy correctly - each exclusion file (or match depending on wildcards) should be on a new line within the file. So far I've been unable to reproduce the behaviour you're experiencing.
Is the exclude.txt listing you've given above a test file, or are they the actual css names?
What are the names of the other files that your batch file is supposed to copy?
Edit:
That the xcopy is failing to exclude further files after a single match is giving me most pause. I thought it might be to do with the type of carriage-return that was used in the exclude file, but xcopy handles unix-style carriage-returns just fine.
Can you re-verify that the correct exclude file is being used?
Try forcing it to save with ANSI encoding on your text editor.
I was having a similar issue and that did it.

Resources