I'm using the Javascript files outputted by GWT in a Windows 8.1 app, however as well as being UTF-8 encoded the files also need the Byte Order Mark at the start.
(See this question for why: http://social.msdn.microsoft.com/Forums/windowsapps/en-US/dd352270-8790-4b48-8492-17a4a6875e99/why-the-utf8-with-bom-marker-requirement )
Not sure if it's relevant, but I'm building GWT using Maven.
Is there anything I can change in the Maven pom.xml file that will output the files encoded in UTF-8 with the BOM?
Or a change to GWT config file?
Thank you for your help, I've been trying to figure this one out all afternoon!
Just in case anyone stumbles across this question in the future and wants an answer...
I couldn't find a way to do this with GWT, so I added some code to a .bat build script that runs.
Before running this script you will need to save an empty file (filewithbom.txt) that contains only the UTF-8 Byte Order Marker (0xEF 0xBB 0xBF if you're interested). This can be done by saving an empty file in Notepad, and being sure to set the encoding to UTF-8.
You will also want to change the CHANGE_DIR directory.
set OLD_DIR="%CD%"
set CHANGE_DIR="[PATH TO DIRECTORY WITH FILES TO CHANGE]"
set BOM_FILE="filewithbom.txt"
cd %CHANGE_DIR%
for /R %%f in (*.js, *.html) do (
type %BOM_FILE% >> tempfile.txt
type %%f >> tempfile.txt
xcopy /Y tempfile.txt %%f
del tempfile.txt
)
cd %OLD_DIR%
This loops through the CHANGE_DIR directory and it's subfolders, and adds the contents filewithbom.txt to the start of every file with a filename ending .js or .html.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed last year.
Improve this question
I just discovered that GIMP 2.10 removes JPG EXIF data because of the "PENTAX" in uppercase present in the EXIF data (the bug is described here and here).
Tried Exif Pilot freeware and found out the EXIF fields:
Make=PENTAX
Model=PENTAX K-x
Fixing them to "Pentax K-x" and "Pentax" solves the problem but requires me to do it manually one by one in Exif Pilot GUI.
Is there any way to do this as batch for a whole folder with JPG files? I tried to find some Exiftool parameters to replace "PENTAX" with "Pentax" but to keep the model information correctly but no success so I would appreciate help.
thanks
Using exiftool, you could use this command
exiftool -api "filter=s/PENTAX/Pentax/" -TagsFromFile # -Model -Make /path/to/files/
The -api Filter option will do a regex substitution changing PENTAX into Pentax. The -TagsFromFile option will copy the modified Model and Make tags back into the file. It will not affect any file that doesn't contain PENTAX in those two tags.
This command creates backup files. Add -overwrite_original to suppress the creation of backup files. Add -r to recurse into subdirectories.
Windows is lacking in having the generic command grep for this common task on many other systems. The jpeg files are binary but like a PDF the Meta data itself is held as plain text. Do check your text string is similar to below otherwise you will/may need to parse both PENTAX entries separately as single words.
So in this fixed case it it should be easy to use any binary file reader / writer and "Find aNd Replace" the text string. Just ensure it is byte for byte the same length.
Find =PENTAXPENTAX K-x
Replace =PentaxPentax K-x
DO NOT use Notepad and sadly the native cmd tool Debug.exe was removed long ago. However you might use inbuilt PowerShell of which lit is an advocate. :-)
You could use the well known exiftool but that is yet another exe to add to your dedicated file utilities collection.
Otherwise consider downloading a more universal small CMD batch file like dbenhams jrepl.bat which can be used for hundreds of other file type tasks.
jrepl PENTAXPENTAX PentaxPentax /M /f user-default-avatar.jpg /o -
So the code you need to consider is how you write a loop for doing all your files and thus I will suggest you use For /? and look at the options to add a folder of files something like For %F in (*.jpg) do jrepl ... However, as there are no error checks or backup, I suggest it be something like this
#echo off & Title Replacing PENTAX
set "Find=PENTAX"
set "Replace=Pentax"
for %%F in (*.jpg) do #(
echo replacing %find% in %%F
if not exist %%~nF.bak copy %%F /B %%~nF.bak /B >nul
#jrepl "%Find%" "%Replace%" /M /F %%F /o -
)
I'm looking for a way to run an .exe file and control it by hooking into it's API. The program is Solibri IFC Optimizer (link) and from what I've discovered there is no published documentation about it's API. Is it still possible to control the program without using it's GUI?
My goal is to create a script (.bat or similar) that does the following:
Start program (Solibri IFC Optimizer)
Open file (From hard-coded folder path)
Run process (Optimize IFC file, without zip packaging)
Save file (To hard-coded folder path)
Exit
This script is going to be scheduled and run automatically.
I've searched for similar topics here in Stack Overflow but couldn't find any relevant matches. I'm a novice at this but know some basic programming. This might be silly questions but I would really appreciate any tips and if you guys could point me in the right direction.
Thank you for your very quick replies! I actually got my hands on some documentation about how to control and automate "Solibri IFC Optimizer" by hooking into its API. From what I know, this documentation isn't published somewhere on the internet yet so I would like to share it. This is how to control the program from the Windows command prompt or by using a .bat file:
Solibri IFC Optimizer for Command Line Tool
Example:
c:\Program Files\Solibri\IFCOptimizer>"Solibri IFC Optimizer.exe" -in=d:\temp\model.ifc -out=d:\temp\model_optimized.ifc
Usage:
"Solibri IFC Optimizer.exe" [-license] [-help] [ [-rounding] [-force] -in=dir|file1[;file2;file3;...] [-out=[file|dir [-ifczip|-ifc] [-suffix=_optimized] ]]]
Description:
Solibri IFC Optimizer is used for optimizing Open Standard IFC files.
Optimization is lossless and compression is approximately 5-10%.
Parameter List:
-license : Print license on screen and ignores other options.
-help : Prints this help message and ignores other options.
-rounding : Use floating point rounding.
-force : Force to overwrite existing compressed file(s)
* Default action is to ask for confirmation.
-in : Source folder (optimizes ifc files from the folder)
or file(s) (separated by ';').
-out : Destination file or folder for compressed file(s).
* If destination is a file then -ifczip -ifc & -suffix are ignored.
-ifczip : Forces output file(s) to be compressed .ifczip file(s)
-ifc : Forces output file(s) to be uncompressed .ifc file(s)
By default output file(s) will be compressed .zip file(s).
* Last specified option will be used.
-suffix : Suffix to be added to compressed file(s)
* Default suffix is "_optimized".
After receiving the documentation posted above, I managed to complete the script but I never posted it here. I'll post my solution for other people to find and use:
#echo off
SetLocal EnableExtensions EnableDelayedExpansion
chcp 65001
REM ----- DESCRIPTION -----
echo Optimizing IFC files located in the same directory as the script, using Solibri IFC Optimizer.
REM ----- LINE BREAK (REQUIRES TWO TRAILING BLANK LINES) -----
set br=^
REM ----- ITERATING IFC OPTIMIZATION AND FILE REPLACEMENT -----
set /a count=0
for %%f in (*.ifc) do (
"c:\Program Files\Solibri\IFCOptimizer\Solibri IFC Optimizer.exe" -in="%cd%\%%f" -out="%cd%" -ifc -force
set filename_ext=%%f
set filename=!filename_ext:~0,-4!
move "%cd%\!filename!_optimized.ifc" "%cd%\!filename!.ifc"
set "file_list=!file_list! !filename! !br!"
set /a count += 1
)
msg * "The following !count! IFC files were optimized: !br!!br!"^
!file_list!
exit
When I run this file:
xcopy .\*.odt .\source.zip
I am prompted to specify what source.zip is:
xcopy .\*.odt .\source.zip
Does .\source.zip specify a file name
or directory name on the target
(F = file, D = directory)?
In my case when it find the .odt file to copy the file and place in the same directory but with new name source.zip. Is there approach to avoid the prompting since I always want destination to be a file not directory.
Any .odt file (being in .zip format in fact) is a binary file, see OpenDocument Document Representation
As a collection of several sub-documents within a package, each of which stores part of the complete document. This is the common
representation of OpenDocument documents. It uses filename extensions
such as .odt, .ott, .ods, .odp ... etc. The package is a
standard ZIP file with different filename extensions and with a
defined structure of sub-documents. Each sub-document within a package
has a different document root and stores a particular aspect of the
XML document. All types of documents (e.g. text and spreadsheet
documents) use the same set of document and sub-document definitions.
Therefore, you need to treat it as a binary file (read copy /?):
copy /B .\*.odt .\source.zip
Above command would work smoothly only if there will be only one file with extension .odt. Otherwise, it will prompt you for Overwrite .\source.zip? (Yes/No/All):. To stay on the safe side:
from command line for %G in (.\*.odt) do copy /B "%G" ".\source_%~nG.zip"
from a batch script for %%G in (.\*.odt) do copy /B "%%G" ".\source_%%~nG.zip"
%~nG (or in batch %%~nG) explanation: read Parameter Extensions.
I need to create a script, which concatenates multiple text files into one.
I know it's simple to use
type *.txt > merged.txt
But the requirement is to "concatenate files from same day into file day_YYYY-DD-MM.txt" I am a Linux user and Windows batch is hell for me. It's Windows XP.
Windows type command works similarly to UNIX cat.
Example 1: Merge with file names (This will merge file1.csv & file2.csv to create concat.csv)
type file1.csv file2.csv > concat.csv
Example 2: Merge files with pattern (This will merge all files with csv extension and create concat.csv)
When using asterisk(*) to concatenate all files. Please DON'T use same extension for target file(Eg. .csv). There should be some difference in pattern else target file will also be considered in concatenation
type *.csv > concat_csv.txt
At its most basic, concatenating files from a batch file is done with 'copy'.
copy file1.txt + file2.txt + file3.txt concattedfile.txt
In Win 7, navigate to the directory where your text files are. On the command prompt use:
copy *.txt combined.txt
Where combined.txt is the name of the newly created text file.
Place all files need to copied in a separate folder, for ease place them in c drive.
Open Command Prompt - windows>type cmd>select command prompt.
You can see the default directory pointing - Ex : C:[Folder_Name]>.
Change the directory to point to the folder which you have placed files to be copied, using ' cd [Folder_Name] ' command.
After pointing to directory - type 'dir' which shows all the files present in folder, just to make sure everything at place.
Now type : 'copy *.txt [newfile_name].txt' and press enter.
Done!
All the text in individual files will be copied to [newfile_name].txt
I am reiterating some of the other points already made, but including a 3rd example that helps when you have files across folders that you want to concatenate.
Example 1 (files in the same folder):
copy file1.txt+file2.txt+file3.txt file123.txt
Example 2 (files in same folder):
type *.txt > combined.txt
Example 3 (files exist across multiple folders, assumes newfileoutput.txt doesn't exist):
for /D %f in (folderName) DO type %f/filename.txt >> .\newfileoutput.txt
We can use normal CAT command to merge files..
D:> cat *.csv > outputs.csv
cat "input files" > "output files"
This works in PowerShell, which is the Windows preferred shell in current Windows versions, therefore it works. It is also the only version of the answers above to work with large files, where 'type' or 'copy' fails.
Try this:
#echo off
set yyyy=%date:~6,4%
set mm=%date:~3,2%
set dd=%date:~0,2%
set /p temp= "Enter the name of text file: "
FOR /F "tokens=* delims=" %%x in (texto1.txt, texto2.txt, texto3.txt) DO echo %%x >> day_%temp%.txt
This code ask you to set the name of the file after "day_" where you can input the date.
If you want to name your file like the actual date you can do this:
FOR /F "tokens=* delims=" %%x in (texto1.txt, texto2.txt, texto3.txt) DO echo %%x >> day_%yyyy%-%mm%-%dd%.txt
You can do it using type:
type"C:\<Directory containing files>\*.txt"> merged.txt
all the files in the directory will be appendeded to the file merged.txt.
copy is definitely much faster than type - but it sometimes (with large files?) adds a SUB character at the end of the file. So, strictly speaking, it does not simply concatenate the files in the same way as cat in Unix.
So, the correct answer is to use cat - either in something like Git Bash (where it has the same syntax as in Unix), or PowerShell (where it does not).
I have a simple xcopy script that I'm running from the command line that reads a CSV file of directories and file names. I've used a very similar script with no problems before. Here is the script:
Z:\HOME\>for /f "delims=, tokens=1,2,3,4" %i in (Z:\HOME\MissingImages.csv) do
echo f | xcopy "Y:\%j\%k\%l" "C:\Horizon\%j\%k\%l" >> Z:\HOME\MissingImagesLog.txt
However, it is not copying any of the files over
Here is an entry from the log file:
Does C:\Horizon\K\00\6bef500f.IMG specify a file name
or directory name on the target
(F = file, D = directory)? f
0 File(s) copied
It's finding the images because if I change the root directory to something else the script will just populate the log file with 0 File(s) copied for all entries, so the files are there and can be seen...
Also, the Z:\ drive is on a network and not local, but again I have used a very similar script across a network without problems (it just takes longer).
I've tried different options like /i, /s, etc. but I can't seem to get it to copy any files over.
xcopy will also report 0 File(s) copied if you use forward slashes "/" in paths instead of backslashes "\", though ONLY if you've enclosed the path in quotes.
This fails with "0 File(s) copied"
xcopy "pathname1/file" pathname2\file
This fails with "Invalid number of parameters"
xcopy pathname1/file pathname2\file
This works just fine
xcopy pathname1\file pathname2\file
It asks because it doesn't know whether you want to copy to directory (to be created) or you provide the full target pathname.
This will ask:
xcopy pathname1\file.from pathname2\file.to
However, adding slash will tell that you copy to directory:
xcopy pathname1\file.from pathname2\to\
But I haven't found the way to tell explicitly that I want to copy and rename file, except
echo Y | xcopy pathname1\file.from pathname2\file.to
I played a bit with your case (with for, do and xcopy) and found out that even if it asks Does SOMEFILE specify a file name or directory name on the target (F = file, D = directory)? it is provided with f from echo and it's copied successfully. Thus, it's not a problem with file/directory specifying, but with copying through network itself.
Well, that's annoying; I found the issue. It looks like when I generated my CSV file, it put a space at the end of each line, so xcopy was looking for files that had a space after the extension.
The thing that was throwing me off was that it was finding the files, but couldn't copy them, making me think it was a network or xcopy issue.
I just ran a sed script to remove the eol spaces and the xcopy script is now working as expected.