How do I use command prompt to identify derivative generation drop off? - pdf

I have one folder of approximately 7500 pdfs and a second folder with approximately 7300 tiff derivatives. Somewhere over the past 4 days of processing, intermittent tiff derivative generation failure occurred. How do I identify which files dropped off?
So far Ive tried:
diff -rq folder_pdfs folder_tiffs
However that reports all files as different given the difference in file extensions.

How do I identify which files dropped off?
Use the following batch file.
MissingFiles.cmd:
#echo off
setlocal
for /f %%f in ('dir /b folder_pdfs') do (
if not exist folder_tiffs\%%~nf.tiff (
echo folder_tiffs\%%~nf.tiff
)
)>>MissingFiles.txt
endlocal
Notes:
MissingFiles.txt will contain the list of missing files.
Example:
F:\test>dir /b folder_pdfs
1.pdf
2.pdf
3.pdf
4.pdf
5.pdf
F:\test>dir /b folder_tiffs
1.tiff
3.tiff
5.tiff
F:\test>MissingFiles.cmd
F:\test>type MissingFiles.txt
folder_tiffs\2.tiff
folder_tiffs\4.tiff
Further Reading
An A-Z Index of the Windows CMD command line - An excellent reference for all things Windows cmd line related.
dir - Display a list of files and subfolders.
for /f - Loop command against the results of another command.
parameters - A command line argument (or parameter) is any value passed into a batch script.

Related

Batch Files Pull Variables from Text Document

I'm in the process of remuxing a bunch of videos I have. Once I have them remuxed, they all have different audio offsets that I need to implement. I have a batch file that will go through every file in the folder and do one offset. However, I would like to have it go into a text document (Offsets.txt) and pull info from it.
This is my "Offsets.txt"
Bio Broly.mkv: +1.112450
Bojack Unbound.mkv: +1.034330
Broly Second Coming.mkv: -1.166504
Broly Legendary Super Saiyan.mkv: +1.3140975
Coolers Revenge.mkv: +.032810
Dead Zone.mkv: +0
Fusion Reborn.mkv: .944 Seconds
This is my "AV Sync Fix.bat"
#echo off
set /P Delay=What is the delay you would like to use?
set /P Track=What track would you like to change?
for %%i in (*.mkv) do "C:\Program Files (x86)\MKVToolNix\mkvmerge.exe" -o output/"%%i" -y %track%:%delay% "%%i"
Echo Your files were moved to a folder called output. Press ENTER to quit:
pause
Exit
I would like it to run that "for" command for each video line, filling in the delay automatically. I still want to manually put in the track.
Just to make sure I said it right. I want to start the batch file, still put in the track to change, then it will run the "for" command on each mkv file and use the corresponding delay for each. Whether I have 3 files, or 80 files. And it will only run on the files in that list.
Thanks in advance!
And it will only run on the files in that list.
Okay, then you should enumerate the list, not *.mkv:
#echo off
set /P Track=What track would you like to change?
for /f "usebackq delims=" %%O in ("offsets.txt") do (
for /f "delims=: tokens=1,2" %%a in ("%%O") do (
"C:\Program Files (x86)\MKVToolNix\mkvmerge.exe" -o output/"%%a" -y "%Track%:%%b" "%%a"
echo:&echo:&echo:
)
)
pause
Sync offsets should be set in milliseconds (see mkvmerge documentation) unless you want to have a headache dealing with floats via the limited batch-file integer arithmetic.

DOS Batch File Variable Modifier Returns Blank

I have a DOS batch file that will create a report listing files contained within a folder tree. The code below produces the desired output for over 115,000 files. However, 13 records are produced with blank date/time and file size. When I manually execute the DIR command (without the /b option), the desired file information is presented. Can this be corrected without adding considerable workaround code?
FOR /f "tokens=*" %%A IN ('DIR "<Path>" /a:-d /b /s') DO (
ECHO %%~tA %%~zA %%~dpA %%~nA %%~xA >> test.txt
)
(FOR /f "tokens=*" %%A IN ('DIR "<Path>" /a:-d /b /s') DO (
if exists "%%~A" ECHO %%~tA %%~zA %%~dpA %%~nA %%~xA
)) >> test.txt
The main reason for not obtaining a date/filesize is that the file can not be found.
How does your code work?
The for /f starts a separate cmd instance that runs the dir command.
When all the data has been retrieved and loaded into memory (that is, the cmd/dir command finished), then the for will start to iterate over the retrieved lines. Some time have passed between the information retrieval and the information processing.
In this time, "maybe" the problematic files have been moved/deleted/renamed and they can no be accessed to retrieve their properties. So, first check if the file still exists
The aditional parenthesis and redirection change are to avoid having to open the target file for each echo operation. This way, the file is opened at the start of the for command and closed at the end.

Script copies more then *.pdf

I have a script that copies several PDF Files, and it places it to the corresponding folder.
Script:
pushd "\\share\folder\"
for %%p in (*.pdf) do for /f "tokens=1 delims=_" %%n in ("%%~np") do (
copy "%%~fp" "\\share2\folder\%%~n\%%~nxp"
)
But it also copies files that are named like this: Test.pdf2098 or hello.pdf20j93f2
I just want it to copy *.pdf files and not PDF's that are invalid.
Add an if check to verify the extension
pushd "\\share\folder\"
for %%p in (*.pdf) do if /i ".pdf"=="%%~xp" for /f "tokens=1 delims=_" %%n in ("%%~np") do (
copy "%%~fp" "\\share2\folder\%%~n\%%~nxp"
)
David Ruhmann provided a workaround, but did not explain why your code fails.
The problem is that files on NTFS volumes that do not meet the old 8.3 short file naming standard are automatically assigned alternate short file names that do meet the standard. Files like xxx.pdf2098 would be given a short name that has a .pdf extension.
The windows commands like COPY, MOVE, FOR, etc. that search file names all attempt to match both the long and the short name, thus leading to your problem.
It is possible (and often recommended) to disable short file name generation on NTSF volumes, but any existing short names will remain and potentially still cause problems.
So David Ruhmann is correct in suggesting that you verify the file extension of each file.
Another frequently used method to verify the extension is to pipe DIR /B to FINDSTR:
for /f "eol=: delims=" %%p in (
'dir /a-d /b *.pdf^|findstr /lie ".pdf"'
) do for /f "tokens=1 delims=_" %%n in ("%%~np") do (
copy "%%~fp" "\\share2\folder\%%~n\%%~nxp"
)

Batch file that takes the file for the previous day only and copy it elsewhere

OK, so I've done a bit of research but have hit a bit of a hurdle here. What I'm trying to do is, (using event scheduler), run a batch daily, that takes the "ips*.csv file (* is just the date format) for the previous day only and copy it elsewhere, for my test I used "destiny ips" folder. I think I've messed up on the last hurdle.
FORFILES /P "C:\Users\J\Desktop\ips bat\source ips" /M "ips*.csv" /C "cmd /c XCOPY C:\Users \J\Desktop\ips bat\source ips folder C:\Users\J\Desktop\ips bat\destiny ips" /D -1
Thanks for any help in advance.
Jonny
for /f "delims=" %%i in (
'dir /b /o:-d "c:\users...etc...ips*.csv" ' ) do (
xcopy /d "%%i" "C:\Users\J\Desktop\ips bat\destiny ips\" &goto :eof
)
should do this very simply (in fact, it can all be on the one line) It will copy only the very latest version of the file to the destination - and then only if the destination file does not already exist (or is different from the version in source.) This should take care of any non-operational days like weekends or public holidays.
If the destination keeps ALL of the history (ie. there may be ips*.csv files in the destination that are not in the source, but not vice-versa (other than the new one for "yesterday") ) then simply
xcopy /d "c:\users...etc...ips*.csv" "C:\Users\J\Desktop\ips bat\destiny ips\"
will suffice.
The critical points are:
the destination ends in "\" to say 'this is a directory name'
the /d which will tell XCOPY to copy only new or updated files.
(It stands to reason that ...etc... is the remainder of the pathname required - DOS is not psychic)
To include special characters in the command line, use the hex code for the character in 0xHH format (ex. 0x09 is theTAB character, 0x22 is the double quote " character.) so "C:\Program Files\" becomes ^0x22C:\Program^ Files\^0x22
FORFILES
/P "C:\Users\J\Desktop\ips bat\source ips"
/M "ips*.csv"
/C "cmd /c
XCOPY ^0x22C:\Users\J\Desktop\ips^ bat\source ips folder^0x22
^0x22C:\Users\J\Desktop\ips^ bat\destiny ips^0x22"
/D -1
I have separated it onto multi-lines for readability, but you will want to put that back into one line.
This looks suspect-:
XCOPY C:\Users \J\Desktop\ips bat\source
Is it correct?

XP Batch scripting - zipping with rinrar looping through a directory *.csv

I have read numerous articles now and it's not clear and there's lots of versions and this that and the other and I have been piecing things together and have got so far, my problem is the 'rar' command doesn't seem to accept my substition variable and instead reads it as a string.
But this is what I have
#echo off
SETLOCAL
set path=%path%;"C:\TEMP\Output"
set _sourcedir=C:\TEMP\Output
set _logfile=c:\temp\Output\zip_log.txt
set _rarpath=C:\Program Files (x86)\WinRAR
echo Starting rar batch > %_logfile%
:: Set default directory
pushd %_sourcedir%
echo Scan Directory is %_sourcedir%
FOR %%f IN (*.txt) DO (
echo %%f
%_rarpath\rar.exe a test
)
popd
ENDLOCAL
#echo on
I have cut some out and chopped it so you only get the essence, I haven't omitted any commands though.
I am trying to loop through the directory and locate all .txt files and zip them into a .rar file.
The echo writes out the correct filenames.
Any ideas?
I think this is your problem:
set _rarpath=C:\Program Files (x86)\WinRAR
In batch files, the environment variable delimiter is a space, so it thinks _rarpath is C:\Program
Enclose the path in double quotes and see if that helps:
set _rarpath="C:\Program Files (x86)\WinRAR"
Also, in your FOR loop change
%_rarpath\rar.exe a test
to
%_rarpath%\rar.exe a test
(or,perhaps this was a typo?)
I don't see where you're asking winrar to do anything with your files? %%f needs to be on the winrar command line somewhere.
Also, you shouldn't need a loop at all for this: rar.exe a test.rar %yourpath%*.csv or similar.