Batch file to list and copy files to another directory - batch-file

I'm a novice with batch files, even though I've had a computer since the mid 1980s. I need to create a (preferably simple) batch file that will list all the directories on drive D:\TAR\ (to a text file maybe?) and append the extension .tar to the directories names. Then I would like to copy all the .tar files(in the text file that was created) on E:\Incomplete\File1.tar to F:\ToComplete\ directory.
I tried doing it from a DOS command prompt, but I couldn't figure out how to put the .tar extension on the directory names and do the copying. I've been googleing, and searching on this site, with no similar problems.
Is there a list on the net that list most of the commands that can be used in .bat files, for example #echo, end, if, then, etc.? I would like to be able have it as a guide. I would appreciate any and all help.
Thank You.

The command prompt has a builtin help command that provides a decent listing of common commands, and each command supports the /? switch to attain more information on it.
You will typically use the for command to enumerate the contents of a directory, and if you need to perform string manipulation on the directory entries you will probably find the command prompt's "delayed expansion" feature useful. This feature is off by default, but can be enabled for an interactive session by running cmd /v:on. (Enabling this feature permanently requires a registry setting.)
In terms of your specific problem here, when you say "all the directories under D:\TAR\", would that be a recursive operation?

Related

Quickest way to create a .bat file (as .txt)

I have a couple lines of code in a batch file in Windows 10 that open a session of Octave, and load a script that uses design parameters contained in a .txt file. The batch file is named (for example) "Design123.bat", and when Octave runs, it automatically finds the design parameters in the file "Design123.txt" by simple string manipulation of the file name, i.e. strrep(filename,".bat",".txt"), where filename = '%~dpn0' is passed to Octave from the batch file. This allows for the contents of the batch file to stay simple and constant, and the file name of the batch file is the only thing tying it to the .txt file.
I do all of this to allow running the Octave script by double-clicking the batch file for convenience, instead of being forced to use the more tedious process of uigetfile in Octave. This works very well, but the catch is that I have to place a copy of the batch file in the same directory with the design (.txt) files (of which there are thousands, but each within their own directory) and give it the same file name to get it to work. Is there a way to quickly create the batch files somehow? The most ideal situation I can think of is to be able to right-click (or somehow select) a .txt design file, and create a batch file (replacing .txt with .bat) and place my lines of code into it.
Any ideas? I have coding experience, but only in software packages like VBA and Octave, not within operating systems themselves, though certainly willing to learn if I could get pointed in the right direction. The design file names follow a distinctive pattern, so they could be filtered easily within an operation on the active "File Explorer" window in Windows 10, if something like that is possible. Thanks in advance.
You might want to compose the answer to your question from calling the script on the right click and running the .m script with command line arguments.
If that fails, uigetfile is certainly not the only method to get file. At the very least you could always copypaste a path string to a folder from explorer to octave function call.
Finally, I guess I'll mention the existence of octave-cli which runs in terminal instead of gui. It might be better suited for running non interactive scripts.

Move files into a jar with a .bat script

Just the title. I'm trying to make a .bat file that moves stuff into a .jar, but I have no idea what to do, or even if it's possible. If it's possible, could I be pointed towards the information that would allow me to create such a .bat file? Thanks.
"A .jar file is just a .zip file with a different extension. Use any zip tool that takes command line parameters like WinZip or 7-Zip, and call it from your batch file passing it the right information in the parameters to add the files. Once you pick your utility app, you can read its documentation to find out what parameters it takes and what order they should be in. (Or more easily, you could just open the file in WinZip or 7-Zip and drag and drop the files in using Windows Explorer and save the time and effort.)" - From Ken White, in a comment
Thank you Ken White, for your answer.
While I do agree not using commands is more convenient, I can't automate moving files without commands or code.
This is a valid answer. But for some reason an arbitrary restriction won't let me mark this post as the answer until two days.

Overwrting multiple file using NSIS Script (how Win Zip extractor does)

I am writing a script using Null Script which install around 6000 files in INSTALLDIR i.e. C:\ABC folder.
I have done this using
File /r "ABC"
in install section.
It is just a simple extractor (no registry entries and no uninstall.exe created during install).
Now, if I run the same exe again then I want my exe to display a message box to the user while overwriting the files containing the options
Yes,
Yes too all, or
exit the installer
i.e. How WinZip software does while extracting the same zip file in the same location multiple times.
If I set the SetOverwrite value to off then during install (2nd time) my EXE just skips the file installation without notifying the user. Also using IFFILEEXIST I can check a single file or *.* files but cannot do one to one mapping.
Please suggest how can I implement this. If this question is already posted then please send me the link.
Thanks in advance.
It is not possible to get this behavior in NSIS when using File /r. You might be able to pull off something similar by generating the file list at compile time by executing a batch file with !system and then check if each file exists and maybe delete the old one at run-time but you are not going to get the dialog without a custom plugin. NSIS itself only supports basic Abort/Retry/Cancel and Yes/No dialogs.
If you only want to use free tools, why not just use 7-Zip to create a self extracting archive?

How do I keep WZZIP from creating a zip that makes a folder when unzipped?

I'm looking at an automated process (utilizing a "DOS" .BAT file) that creates zip files with a simple command like...
wzzip [path][zip file name] [files to be zipped]
...but when a partner receives and unzips these files, it's creating a folder with the name of the zip file and putting the files inside it, and they need (well, or at least prefer) it to just extract the files to the "." folder.
Is there a way to get wzzip to use "." instead of creating an eponymous folder? The only thing I could see in the options list was to maybe hack something out of -r-p (even though I DON'T actually want it to recurse folders when zipping), but I was hoping there might be a better way.
The partner company is apparently running Linux, so while I see that wzunzip has an option to set the output folder that MIGHT override the default behavior, I'm not sure what the app they are using might allow.
Go to http://www.winzip.com/ and download the Winzip Command Line utilities. Install and use WZZIP.EXE.

Sync folders with xcopy/batch based on checksum?

I'm trying to make a simple batch for windows that will basically sync two folders, the catch is that the files in the folders can be named arbitrarily and the snyc should be based on the checksum. I've only found information about xcopy that compares the timestamp so I'm wondering if this is possible in a simple matter at all.
Here is the scenario I'm trying to manage, you've got the "Import Folder" containing the files named A_2.bmp and A_3.bmp and the "Target Folder" containing file A_1.bmp.
File A_2.bmp is infact the same file as A_1.bmp, just with a different name and thus should be skipped, A_3.bmp should then be copied over to target folder and icrementally renamed to A_2.bmp.
This probably sounds more like a work for patching software, but I'm looking for a solution that doesn't require building patches all the time and is open for the user (so he can just drop files into the import folder and run it whenever the need arises)
If there is software for such a thing that is free and can be distributed without installing I would also consider this a good option, but I haven't found anything.
I'm thankful for any advice and help on this matter so thank you very much for your time and help!
You have this command line utility :
http://www.microsoft.com/en-us/download/details.aspx?id=11533
You can then make a bat who simply test the checksum of the files

Resources