Use drag and drop function to select multiple files and process all - windows

I need a way to select several files with check-boxes and drag them all to a batch-file icon. The first step in the script would be to be compressed them into a single zip file before proceeding to the next step. If possible, it would be useful to also end up with each in a separate zip of its own for storage.
I am not sure how to address the for:to commands to allow gathering all selected files into a single zip file in a script. The Windows 'sendto compressed zip' function works perfectly if I select all the files the copy and paste them to the Windows ZF filetype. But I don't know how to access it from within a batch.

Drag and drop multiple files
By default, if you drag a file onto a batch file it is the same as passing the filepath as a parameter. This can be accessed using %%1. Dragging multiple files would have a similar effect and be like calling test.bat file1.txt file2.txt file3.txt. Each "parameter" can be accessed using subsequent variables, %%1, %%2, %%3, etc, up to %%9.
Get more information here.
Zipping files
First you will need a utility that supports command line operations, such as 7-zip. Once you have the appropriate executable in your path, you will need to review the documentation on how to zip files from the command line. Instead of using the paths and filenames, you will use the variables mentioned above.
Here is some pseudo code:
zipfiles output.zip %%1 %%2 %%3 %%4 %%5
Notes
You will not be able to drop more than 9 files.
You may need to confirm that each variable exists. If you try to include %%9 in the zip command but you only dropped 8 files, you may get an error.

Related

How to extract date from filename in batch, and unzip to multiple directories using batch/7z

I am trying to code a script to automatically process some of our daily ftp files.
I have already coded the files to download from the source ftp using WinSCP and calling it in a .bat file, and would ideally like to call it within the same bat. Scripting Language does not matter, as long as I can run/call it from the original batch.
I need will extract the date from a filename, and unzip the contents into corresponding folders. The source file is delivered automatically daily via FTP, and the filename is:
SOFL_CLAIM_TC201702270720000075.zip
The bolded section is the date that I would like to extract.
The contents of the .zip include two types of content, multiple PDFs and a .dat file.
For the supplied date of 20170227, the pdfs need to get extracted to a folder following the format:
\%root%\FNOIs\2017\02-Feb\02-27-2017
At the same time, the .dat file needs to get extracted to multiple folders following the format:
\%root%\Claim Add\2017 Claim Add\02-2017
\%root2%\vendorFTP\VendorFolder
After extracting, I need to move the source zip to
\%root%\Claim Add\2017 Claim Add\02-2017
What is the best way off accomplishing all of this?
I am assuming it would be the for /f batch command, but I am new to batch coding and cannot figure out how to start it from scratch.
I also have 7zip installed, but do not understand how to use the command-line options.
You have asked for a lot in one question, and not shown any code or demonstrated effort on your part.
For the first part, once you have the filename in a variable:
set FILENAME=SOFL_CLAIM_TC201702270720000075.zip
You can get the date part with:
echo %FILENAME:~13,-14%
The syntax: :13,-14 means "Remove the first 13 letters and the last 14 letters." That should leave you with just the date.
When you integrate that into your script, Show Your Code

mass deletion batch file

I have been tasked with stripping out around 50 thousand .INI files from a windows folder that has 58 thousand files in it the issue is that the files aren't in order and removing these manually would be very time consuming.
The files themselves use number Id's as their naming convention and I managed to get an Excel spreadsheet together with all the ID's I need to remove. My question is, can I put these ID's somewhere like a batch file and get it to remove these if so how?
Thanks in advance.
Here is the simplest script that will work:
cd "C:\directory\location\"
del "*.ini" /s
exit
The first line makes sure its in the directory that all the files are in, the second one deletes all the files in the specified folder and all of its subfolders (the subfolders can keep their .ini files if you remove the /s), and the third line quits the batch file. The third line is not necessary. The first line can be revoked if the batch file (.bat) is in the same folder as all of the .ini files.

Drag N' Drop 100+ Files Batch

I've been searching for an answer on the internet and can't seem to get a definitive one. I've been having an issue with getting a .bat file to accept more than 80 files at once for conversion and file look up with a batch script that links to a python script.
Here is an example of what I'm doing, it's easy enough...
#ECHO OFF
python "C:\myDirectory\Conversion_and_Excel_Extractor.py" %*
PAUSE
Again, this seems to work with 80 files drag and dropped unto the batch script but doesn't seem to work with more than that. Is there something I'm doing wrong?
they are located in their own directory. I would prefer to drag the
entire set of files, or the entire directory, into my batch file and
iterate over the files
that's possible:
drag the folder to your batch file and use
python "C:\myDirectory\Conversion_and_Excel_Extractor.py" "%~1\*"
As an alternative you could drag any one of the files to the batch file and use %~dp1 to get the folder and
python "C:\myDirectory\Conversion_and_Excel_Extractor.py" "%~dp1\*"
to process all files in this directory.

Batch file to copy files from multiple folders to a single folder, overriding if date is newer

I would like to be able to copy all files from various folders and combine them into a single folder using a Windows batch file. That is fairly easy to do for me. But if the file already exists on the destination, I would like it to only override the file if it's newer.
copy c:\pics\ to d:\
Thanks.
You can use xcopy for more options if the source dirs are 2-3-5 (write separate xcopy lines for each). If the dirs are too many, you can use archiver like WinRar (or its command line rar.exe) with #list option where are stored the source dirs. In the batch file call RAR 2 times - first to pack all source files to one archive, then to unrar them in single folder (with E option, not X). Finally, you delete the .rar file. See the extra options to skip older files, omit prompts, etc.

DOS Commands- Excluding files in a folder in xcopy

I have a folder containing many other sub-folders.
I am trying to write a batch file which will copy some of the folders to another place on my hard disk. I am using "xcopy" for this. I am facing following problem:
The folder structure is as shown below-
--FolderB1
---FolderB2
---FolderB22
---File1.txt
---File2.txt
---File3.txt
I have some .txt files inside "FolderB1", along with "FolderB2" and
"FolderB22" I want to copy "FolderB2" and "FolderB22" and skip ".txt"
files contained in "Folder B1"
I tried using /EXCLUDE: param of xcopy command, but it is not able to perform this operation. It does not work if I specify the exclusion as \FolderB1\*.txt or something of this sort.
The number of main folders is not known. It can be anything. Also, there is no fix pattern for names of ".txt" files. Have checked this question too, but did not help.
Alternate method or other pointers for the same would be a great help. Thanks in advance.
What you could try to do is to hide the files you don't want to copy, then execute the xcopy, and then unhide the files again.
Look at my answer of question Windows batch script to delete everything in a folder except one. That question was related do deleting files (excluding some files), but you can probably use the same trick for xcopy-ing files.

Resources