batch using 7-zip: compress smallest file first to largest file - 7zip

I have a .bat file that runs 7-zip to compress all files in a directory. The files range in size from 1mb to 500mb and there are 10 files. Every 15 mins a scheduled backup program overwrites 5 of the 10 files. Those 5 files are usually the smallest and the quickest to compress, but 7-zip starts with the largest file first thus missing the 5 files within the 15 minutes. How do I get 7-zip to start with the smallest file first. Any help would be much appreciated.
c:
cd "\Program Files\7-Zip"
7z a C:\WEBDATA C:\FILE1.BAK C:\FILE2.BAK C:\FILE3 C:\FILE4 C:\FILE5 etc...

If all of the files are in the same directory, you can use the sort feature of the dir command to add files to the archive one at a time.
For example, if the files to back up are in a subdirectory called 'files':
for /f %%N in ('"dir /A-D /O:S /B files"') do (
7z a backup.7z files/%%N
)
Based on your description this should be sufficient, but if the files are in various locations you may need to get fancier. I haven't tried it myself, but I would expect you could loop through a list of directories, writing each size / filename to a temporary file, then using the sort command on that file.

Related

Counting number of files in subfolders and writing to text file

I need to regularly count the number of files in many subdirectories from many computers. I'm looking for a batch file that will output a recursive count of all files, and then output this to a text file. Ideally, I want this without having to type out the complex name for each subdirectory.
Here is an example of what I have:
Parent_directory.
Sub_directory_A. 1000 files
Sub_directory_B. 2000 files
Sub_directory_C. 3000 files
I've found this code online, but it only counts one subfolder, and I have to navigate into that subfolder first: attrib.exe /s /D *.*|find /c /v "" >> filecount.txt. Therefore, this is very close.
How can I start in my parent directory and get a count of the files in folders A, B, and C broken out individually and then copied to a .txt file?

Search multiple files in Windows, copy to new folder

I'm running Windows and I have a massive group of .pdf files (several thousand) all stored in one large directory, and then all variously organized into a variety of subdirectories within that main directory.
e.g.:
K:\OriginalDirectory [main directory]
K:\OriginalDirectory\2010 [subdirectory 1]
K:\OriginalDirectory\2011 [subdirectory 2]
K:\OriginalDirectory\2013 [subdirectory 3]
My problem: I need to copy-and-paste about 1900 of these files into a new directory. The Windows "find" function won't let me do this, as trying to use the "or" operator to combine 1900 unique file names exceeds the 255 character limit for "find."
So I tried the following (based on another StackOverflow answer), using the command line:
C:\OriginalDirectory>for %I in (doc1.pdf doc2.pdf doc3.pdf) do copy %I C:\SomeOtherDirectory
This works, but doesn't search the subdirectories. Also, it requires me to type out all 1900 file names, which isn't ideal.
Is there a way for me to complete this task using just the command line that searches all subdirectories within my main directory AND doesn't require me to type out 1900 file names?
You can use a batch script which would do the work.
Found on: Windows batch copy files from subfolders to one folder
Adjusted for you it should be something like:
pushd C:\OriginalDirectory
for /r %%a in (*.pdf) do (
COPY "%%a" "C:\SomeOtherDirectory\%%~nxa"
)
popd
edit cause of comment
Copy only those files which are in a list: (Again not sure about the type "C:/my..." because i am currently not able to test it but should work in such a way)
pushd C:\OriginalDirectory
for /r %%a in (type "C:/myFileList.txt") do (
COPY "%%a" "C:\SomeOtherDirectory\%%~nxa"
)
popd

Windows Batch File to Delete Audio Files, with Length Requirement

and thank you for any help. I have tried searching for an example on how to accomplish the following, but haven't found anything. Any help would be appreciated as I have no experience in creating a BAT file!
I have a third party program that records audio, and generates an .mp3 file from it. Every 24 hours, it generates a new folder, and begins the process all over again. The problem is, even the slightest bit of sound will generate an .mp3 file. I am left with thousands of .mp3 files that are less than 1 second. I would like to delete all audio files in all of the subdirectories with a length of less than 2 seconds. How can I go about this, and is a BAT file the correct way to accomplish this? The manual way of sorting the files in the many, many directories is a very time consuming process as 20 - 30 days of files will be generated before I am able to go through them.
For a GUI solution: The shareware uncrippled Total Commander can list a full directory tree (control B) and sort by filesize (control F6) and can also display only MP3 files if needed.
This task would just need you to mark the filesizes less than x MBytes in a single pane and then you can delete them all at once.
Another solution is available with a batch file to delete MP3 files of 2.999 seconds or below:
- change [210] to [10] to delete files up to 1.999 seconds.
Download Mediainfo command line version from SourceForge
Change the path to the executable in line 2 below
Launch this batch file in the main folder of the tree of files
If the del commands you see on the screen are right then remove the echo and run it again to delete the files.
#echo off
set "exe=c:\Util\MediaInfo\MediaInfo.exe"
for /r %%a in (*.mp3) do (
"%exe%" -f "%%a" |find "Duration" | findstr /r ": 00:00:0[210]" >nul && echo del "%%a"
)
pause

How to add a file in multiple zip files?

Im trying to move a picture in every zip folder in current directory. I searched online for some guidance on how to do it using batch (.bat) and the only solution I figured out is to make a macro of it but it takes too long for it to complete.
Edit:
I have 50 zip folders which I want to add a picture inside each one in a faster way other than draging the picture each time inside each of the 50 zip folders.
I would appreciate any other ideas and help you could offer.
Test this on some sample zip files in a test folder. It assumes 7-zip is in the folder shown.
It's not so much faster as it is easier, without manually manipulating the files.
The actual zipping speed will be pretty much the same.
#echo off
for /f "delims=" %%a in ('dir *.zip /b /a-d') do (
"C:\Program Files\7-Zip\7z.exe" a "%%a" "my-picture.jpg"
)
pause
Adds (or updates) README.txt in the zipfiles foo.zip and bar.zip from README.txt in the current directory:
$ for f in foo.zip bar.zip ; do zip -u $f README.txt ; done
You can package files into a zip file using the Winzip utility. It must be installed on your computer. Follow these steps:
Select the files you need and click on any of the selected ones.
Select Add to Zip
In the Add window, in the Add to Archive field, specify the path and name of the archive to be created.
The ZIP file is saved at the path you specified.

DOS Batch file to move 2000 files every 10 minutes

Is it possible to create a DOS script that will move 2000 files to another folder every 10 minutes?
For example:
C:\MyFolder\
Every 10 minutes move 2000 files to C:\MyNewFolder\
Thank you!
I would use something like xcopy as recommended, however I would use the date flag to specify only copying new files. Just omit the date and it will copy only newer files.
/C Continues copying even if errors occur.
/D:m-d-y Copies files changed on or after the specified date.
If no date is given, copies only those files whose
source time is newer than the destination time.
/E Copies directories and subdirectories, including empty ones.
xcopy C:\Source Z:\Destination /C /D /E
Use Schtasks.
You may want to look here: http://technet.microsoft.com/en-us/library/bb490996.aspx

Resources