CMD file to backup external hard drive - windows-10

I have an i7 processor on a laptop with speeds of approximately 2.8 GHz With 3.5 GHz turbo boost.
I want to create a CMD file to copy 20 directories From 1 external solid-state hard drive to a second external solid-state hard drive.
Additional requirements are:
Output a log with only the final summary from each of the major directories.
Save the output to a text file in C:\data. I want to only output the summary table for each directory copied with column headings total copied skipped mismatch failed extras and row headings dir files bytes and times?
While doing the copy pause between directory copies so all data will be copied and not be fragmented in memory. I plan on running this at night.
I am not sure how to handle the pause nor the time for each pause? For example, some of my copies take almost an hour even on solid-state external drives. Other directories are relatively short.
The code I'm currently running is robocopy "e:\bundle" "f:\bundle" /E /256
Help please! Thank you.
MM

As far as I'm aware, you shouldn't need to add any kind of pause between each robocopy command, I've never had to in any of my personal or business use.
As far as getting logging and simplifying things, you can use the following:
F:
mkdir AcademicSupport bundle mmstat
call :script >"C:\Data\Backup-%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%-%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%.txt"
:script
robocopy "E:\AcademicSupport" "F:\AcademicSupport" /e /256 /tee
robocopy "E:\bundle" "F:\bundle" /e /256 /tee
robocopy "E\mmstat" "F:\mmstat" /e /256 /tee
timeout /t 30 /nobreak > NUL
/tee on robocopy will output the results to the console window, which because of call :script will be logged to the global log file created by call :script >

I am working out the details but the following line of code worked for me.
robocopy "E:\AcademicSupport" "F:\AcademicSupport" /E /256 /NC /NFL /NS /NDL /NP

Related

How to write Batch script to do something based on windows version

I am fairly new to writing batch scripts and our system has just thrown me a slight curve ball.
We are getting new computers with Windows 10 and Office 16. We also still have Windows 7 and Office 14 PCs are the network that have not been upgraded yet.
I currently have a batch file that does an xcopy on execution that checks an excel file on a server against a version of the same file on the users local machine. If the server version is newer, it copies over the local version then opens and runs the excel file.
I need to update my batch to accomodate both versions of excel when it needs to open and run the file.
I can check either on windows or excel version as they are married together, but I'm open to whichever method is more reliable.
I was playing with WMIC which returns the version of windows reliably on our machines. I tried other scripts from my research on the web and they did not function as I would have liked.
Here is my current code:
set "source=\\s001\FOLDER\EXCELFILE TOOL.xlsm"
set "target=C:\Apps\EXCELFILE TOOL PROGRAM\"
xcopy "%source%" "%target%" /y /d /h /k /r
START "" "C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.exe" /e "%target%\EXCELFILE TOOL.xlsm"
EXIT
Before the "START" line, I need to check which version of windows or office is on the machine, then modify the start to be one of these two options:
Option 1
START "" "C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.exe" /e "%target%\EXCELFILE TOOL.xlsm"
Option 2
START "" "C:\Program Files (x86)\Microsoft Office\root\Office16\EXCEL.exe" /e "%target%\EXCELFILE TOOL.xlsm"
Any help would be really appreciated, thanks!
If you're just wanting to start Excel, searching directories should be unnecessary.
Once installed Excel would have a registry sub-key created under:
"[HKEY_LOCAL_MACHINE|HKEY_CURRENT_USER]\Software\Microsoft\Windows\CurrentVersion\App Paths"
Most likely named:
"HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App Paths\Excel.exe"
Where the Default value data holds the fully qualified path to the application.
With entries under this key, simply entering the applications name should run it:
Start Excel.exe
The REG_SZ data entry can be used with or without its .exe extension.(If necessary, the ShellExecuteEx function adds the extension when searching App Paths subkey).
You could therefore simply use:
Start Excel
If using the method suggested throughout the majority of the comments then you'd need to use Excel.exe as part of your search mask!
The example below, utilises an additional For loop, to allow for checking in both Program Files and Program Files (x86)
#For %%A In ("%ProgramFiles%" "%ProgramFiles(x86)%" 2^>Nul
) Do #For /F "Delims=" %%B In ('Where /R %%A Excel.exe 2^>Nul'
) Do #Start "" "%%~B"
You could of course ignore the outer loop if you're sure that the installed version is always installed to Program Files (x86).
#For /F "Delims=" %%A In ('Where /R "%ProgramFiles(x86)%" Excel.exe 2^>Nul'
) Do #Start "" "%%~A"
The above two examples could be left as one line, if you're not interseted in maintaining lines of no more than 80 characters.

Split large amount of wav files to small parts

I have large amount of wav files (over 50 000) and I need to split every wav file to 10 second long parts. It's nearly impossible to do it one by one, so my question is: is there any way to do it in ffmpeg or for example in sox? I'm an amateur, so I need exact instructions. Please, if you can, write it like you would for a dummy :)... (I'm a Windows 7 user)
Here is my try with sox
Thank you!
I had exactly the same task few days ago. I prefer to do it on Linux OS machines, but I had to do some demonstration on Windows machines so I have written this batch file using SoX:
#ECHO OFF
rem Author: PetarF, 2017-07-01, v0.1
rem
rem Example of how to do batch processing with SoX on MS-Windows.
rem In this example, for every .wav file in folder the splited .wav file ends up in a folder called as original file without extension
rem In my case, this file has to be run as administrator
rem
rem USAGE:
rem Place this file in the same folder as sox.exe (& rename it as appropriate).
rem Place .wav files that has to be splited in same folder as sox.exe
ECHO Split started
cd %~dp0
for %%A in (*.wav) do (
mkdir %%~nA
sox %%A %%~nA/%%~nA_.wav trim 0 10 : newfile : restart
echo Created folder %%~nA with splited files
)
echo SoX has splited files...
pause

Move 300 images from a folder (contains 800 images) to another based on file name list

I need to move 300 images from a folder (contains 800 images) to another folder. The file name list of these 300 images are available in the excel format. Is it possible to move them via programming instead of search the file and move it one by one? Our IT told me he can't separate these files. Do you have any solution? Many thanks in advance!!!
Here's one way of doing this - I am assuming you are on Windows. First, save text file called ListOfImages.txt that contains the names of the images you wish to move - put one image on each line and include the extension. Then, save the following into a file called movefiles.cmd:
#echo off
set Source=C:\Users\YourName\Desktop\moving\MovingFrom
set Target=C:\Users\YourName\Desktop\moving\MovingTo
set FileList=C:\Users\YourName\Desktop\moving\ListOfImages.txt
echo.
if not exist "%Source%" echo Source folder "%Source%" not found & goto Exit
if not exist "%FileList%" echo File list "%FileList%" not found & goto Exit
if not exist "%Target%" md "%Target%"
for /F "delims=" %%a in ('type "%FileList%"') do move "%Source%\%%a" "%Target%"
:Exit
echo.
echo press the Space Bar to close this window.
pause > nul
You will want to change the variables for Source, Target, and FileList to match where you have those folders and the ListOfImages.txt on your machine. After you have saved this file (make sure it has the .cmd extension, you should be able to double-click it and it will run the commands in your Command Prompt.
For example, say my MovingFrom folder contains the following:
And I only want to move Image1.png and Image2.png -- then my ListOfImages.txt file would like this:
After running moveFiles.cmd (provided I have changed the necessary variables to point to the right folders/places on my machine), my MovingTo folder should contain the following:
Notice that Image2.png was not moved because it was not listed in the ListOfImages.txt text file.

How do I get rid of errors in .bat file that aren't affecting outcome of the script?

I have an application calls the below command:
C:\Users\212340141>"C:\Program Files\Microsoft Office\Office14\excel.exe" /e "C:
\My Programs\CPU Analysis\data\IOParse.xlsm" "-iodumplocation"C:\My Programs\CPU
Analysis\iodump\065901_iodump.txt""
When I run this command, it opens excel, passing in the C:\My Programs\CPU Analysis\iodump\065901_iodump.txt path as a parameter for the excel book to use in the macros it runs automatically. The macros run correctly and the file is modified correctly, but I get the following errors when I run the command:
How can I get rid of the errors?
Answer
As mentioned in the accepted answer, excel was trying to open multiple files because of how I wrote the command. The way I solved this is I created a text file to hold the path I was trying to pass into the macro. The macro would open the text file and read the path to get the path it needed. This is much cleaner and easier than trying to get the path from the command line.
Description of the startup switches for Excel lists and describes the optional switches which can be used on starting Excel. /e is listed on this page written by Microsoft. But -iodumplocation is definitely not a command line switch for Excel.
Using double quotes within a double quoted string is always a mistake on command line and the result is unpredictable as depending on code of command line parser, see answer on Why double quotes should be always only at beginning and end of an argument string?
The command line used is obviously interpreted by Excel as
"C:\Program Files\Microsoft Office\Office14\excel.exe" /e "C:\My Programs\CPU Analysis\data\IOParse.xlsm" "-iodumplocation" C:\My Programs\CPU Analysis\iodump\065901_iodump.txt""
which results in
/e ... starting without displaying the startup screen and without the creation of a new workbook.
C:\My Programs\CPU Analysis\data\IOParse.xlsm ... opening this marco-enabled workbook file.
-iodumplocation ... the failed attempt to open a file with name -iodumplocation.xlsx in current working directory.
C:\My ... the failed attempt to open a file with name My.xlsx in root of drive C:.
Programs\CPU ... the failed attempt to open a file with name CPU.xlsx in subdirectory Programs of current working directory.
Analysis\iodump\065901_iodump.txt"" ... the failed attempt to open a file with invalid name 065901_iodump.txt"" in subdirectory Analysis\iodump of current working directory.
I can't suggest a correct command line as I don't know what -iodumplocation should be.

How to add files/folders to multiple zip files at once with WinRAR?

Is there any way to add files/folders to multiple zip files at once. For example:
Updates:
folder1
folder2
file1
file2
Archives:
archive1.zip
archive2.zip
archive3.zip
I need to add updates to all archives without opening all of them and pasting updates in there.
Any way to do this?
Or is there another archive program that can do this?
This can be done using a batch file and for example WinRAR.
#echo off
if not exist archive*.zip (
echo There are no archive*.zip files to update in
echo.
echo %CD%
echo.
pause
goto :EOF
)
set "ErrorCount=0"
for %%I in (archive*.zip) do (
"%ProgramFiles%\WinRAR\WinRar.exe" u -afzip -cfg- -ep1 -ibck -inul -r -y "%%I" folder1 folder2 file1 file2
if errorlevel 1 (
echo Error on updating %%I
set /A ErrorCount+=1
)
)
if not "%ErrorCount%" == "0" (
echo.
pause
)
set "ErrorCount="
For each archive*.zip file WinRAR is called to update the ZIP file with the two folders and the two files.
The batch processing finishes without printing any message and without pausing if all ZIP files found could be updated successfully. Otherwise the batch file outputs which ZIP file could not be updated for example because of read-only attribute set, and pauses the batch processing before finishing so that the user can read the error message(s).
For details on the WinRAR command u and the used switches open in WinRAR from menu Help the Help topics, open on tab Contents the item Command line mode and read at least the help pages:
Command line syntax
Commands - Alphabetic commands list
Switches - Alphabetic switches list
For understanding the other used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
echo /?
for /?
goto /?
if /?
pause /?
set /?
You can do it by using 7zip command line version
7z a archive1.zip dir\ -v10k -v15k -v2m #listfile.txt
this will do archive all files and folder is in that folder named 'dir'
and first volume will be 10kb, second will be 15kb and others will be 2mb each except last
and you can use a file that has list of all files named.

Resources