Ghostscript: how to merge PDFs with wild card on Windows - ghostscript

I'm trying to merge all *.pdf in directory :
gswin64c -q -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=Total_Files.pdf -dBATCH *.pdf
This is perfectly work for me on Linux, but when I run it on Windows
I'm getting **Error: /undefinedfilename in *.pdf.**.
Please could some one help me with this.

(My problem was practically exactly the same). My solution (with the help of previous answers) answers the original question slightly better (an actual MS-DOS example is below)
del filename.lst
for %%s in (C:\somefolder\some?wildcards*.pdf) do ECHO %%s >> filename.lst
gswin64c.... #filename.lst
To explain;
'>>' means append in MS-DOS - so firstly we delete file filename.lst
I read (just now in some other place) that %%s in MS-DOS batch files works (instead of %s). Obviously - one day the filenames may contain spaces (as mine did already) so better be safe and quote the filenames. So the better batch file is;
del filename.lst
for %%s in (C:\somefolder\some?wildcards*.pdf) do ECHO "%%s" >> filename.lst
gswin64c.... #filename.lst
Right now I just used this for inputting many EPS files - but many PDF files work fine too; as in the above example - I actually tested it with both - my result is a PDF with many EPS files in it - and many pages from multiple PDF files in one PDF (as per the question).

There was a previous question on this topic, the answer is the same, Ghostscript does not allow wildcards in the input filename, you must specify each file you want to have as input.
Why does it work on Linux ? Because the shell you are using expands '*.ps' to a full list of files before passing the command line to Ghostscript.
To do this in Windows you will need to execute a shell script, pipe the filenames to a file, then supply the file as an argument to GS.
EG, something like
for %s in (*.ps) do ECHO %s >> filename.lst
gswin64c.... #filename.lst

As alternative to the for loop
dir /b /o:n *.ps > filename.lst
gets the job done (/b to get the files only, /o:n to sort by name).
To solve the sorting problem completely, you could rename the first 9 files to 01->09, or open the output file in notepad and handle these few cases manually. But if you will have more than 100 files, this could be bothersome.
Sorry to stir up this one year old thread, which helped me with my problem, but I thought using 'dir' is easier, more flexible and doesn't need you to delete the file list before starting.

Related

windows command prompt substring in a for loop

I have to say before I describe my problem that I am new in performing command line prompts (Windows 10).
I have a directory with txt files (among other files). I need to perform a command line executable (txt2las) where the txt files are read and a .las file is written. This is what I have so far as a command prompt for /R %f in (.\*.txt) do txt2las -i %f -o %f.laz
However, this creates files like name.txt.laz. What I want is name.laz, therefore somehow take the substring from beginning till the last four characters. Can someone help me how to do that?
I tried the substring "function" but does not write anything.
You can extract the just the name of the file (without the extension) by using the ~n modifier:
for /R %f in (.\*.txt) do txt2las -i %f -o "%~dpnf.laz"
You can read more about the modifiers in the FOR /? help docs.
Edit per comments:
To ensure it is placed in the same directory as the source, add the ~dp modifiers in addition to ~n. This will extract the drive and path in addition to the file name. Also, you will likely want to wrap this entire output in quotes in the event the path has spaces in it.
... do txt2las -i %f -o %~nf.laz
The documentation can be read by executing for /? from the prompt.

Creating metadata with CMD?

In a security+ class we were shown how to inject exes and etc into a file using CMD line. The command was along the lines of:
CMD > Notepad.exe "file.exe:otherfile.exe"
In his explanation it added Notepad to file.exe by the name of otherfile.exe.
The problem with this is that he claims it is injecting a file directly into that file, but he showed us how the file size doesn't change but total NTFS file system size changes.
I believe he is talking about generic metadata and not changing the file in any way. Can someone please clarify or give me a reference to the command he is talking about or a good explanation?
Try this, it may answer a few of your questions:
md test
cd test
dir
echo this is my file>file.txt
dir
echo alternative data stream>file.txt:hidden
dir
dir /r
del file.txt
dir /r

Combine mkv's in Windows (automated, not using a GUI)

From time to time I receive several mkv's from a server I have. These mkv's are all part of the same recording, but they come in 1 minute chunks, and I don't want to have to take the time to stitch them together manually each time. Can this be done via an automated process in Windows?
EDIT: See my answer below for the solution that worked for me. The post by Endoro also looks promising.
I can give you an example:
#echo off &setlocal enabledelayedexpansion
cd /d "%sourcefolder%"
set "line="
for %%a in (*.mkv) do set line=!line! +"%%~a"
mkvmerge -o "output.mkv" %line:~2%
As I continued researching, I discovered a download page that also contained a review of mkvtoolnix (http://www.fosshub.com/MKVToolNix.html) that referred to some cmd commands he tested along with the standard GUI test. using the "mkvmerge --help" command, I was able to determine the appropriate command to stitch mkv files together. It looked something like this:
C:\Program Files (x86)\MKVToolNix>mkvmerge file1.mkv + file2.mkv --output C:\Users\User1\mkvfolder\combined.mkv
This stitched two mkv files together (that were located in the MKVToolNix folder), and puts the combined.mkv file in a different directory. It seemed to me that changing the source directories for either of the original mkv's (file1.mkv, file2.mkv) should be possible as well, so I next tried this:
C:\Program Files (x86)\MKVToolNix>mkvmerge file1.mkv + C:\Users\User1\Documents\file2.mkv --output C:\Users\User1\mkvfolder\combined.mkv
The above code merged file1.mkv (which I had placed in the mkvtoolnix directory) with file2.mkv (which I had located in a different directory), and placed the merged file (combined.mkv) in a third directory. The merged file ran cleanly in vlc, with no hiccups at the stitchpoint.
TL DR: go to http://www.fosshub.com/MKVToolNix.html, download MKVToolNix, and use the command line to merge mkv's.
You could try using AVIDemux with the --append arg. On this link there is also a batch file example script.

How to use the list files in a given directory via batch file without showing the full path?

I have searched for this everywhere so I hope it has not already been asked, but I have a batch file where the user can write his / her own 'scripts' if you will. When the batch file is ran for the first time it will make a directory under %appdata%\Mellow\Mango\scripts and these scripts will simply be .txt files. Anyway...
I am trying to list the 'scripts' to the user by using dir /b /s *.txt and the output is C:\Users\Tate\AppData\Roaming\Mellow\Mango\scripts\template.txt
My question is, sorry if I got off-topic before, how to display only template.txt and not the full file path. I simply would like to list all .txt files contained in the scripts folder. Thanks in advanced!
Current Output:
C:\Users\Tate\AppData\Roaming\Mellow\Mango\scripts\template.txt
C:\Users\Tate\AppData\Roaming\Mellow\Mango\scripts\another_script.txt
Desired Output:
template.txt
another_script.txt
Simply remove the /s
dir /b *.txt
That should do it :)

how to batch replace the files in a directory windows vista(from .txt.txt to .txt)

I have a couple of flat files(.txt) in a directory.all those files are in the format *.txt.txt so i want to rename it to *.txt ?Is there any simple way to rename all together?
when I tried ren *.txt.txt *.txt is is not working
Any experts please suggest?It is amazing I have not got any answer yet
Please be noted that I need an out of the format filename.txt.
This should work
ren *.txt.txt *.
The reason your command didn't work is because, to windows, the file file.txt.txt is called file.txt with a .txt extension.
Only the last extension is the real extension, the first then becomes part of the filename, hence why your command changes it to what it already is.
If you did ren *.txt.txt *.pdf you would get file.txt.pdf.
My command will just remove the last one, thereby leaving the first, which then becomes the only and real extension.

Resources