After a file has been placed on to the server is there any way to determine whether the file is binary or text? A ColdFusion function along the lines of FileIsBinary() would be nice but I can't find anything like this.
I need to know so I can determine whether or not to use <cffile action="read"...> or <cfile action="readBinary"...>
Would trying <cfile action="readBinary"...> in a <cftry> block and catching any errors be a reliable way of determining that a file is text?
Related
I have got a trace file that is binary in nature. I want to convert it to a text file and convert the data inside it to decimal form. I mean I am not sure, how to do this. This .trc file contains data in the form of telegrams and I want to extract particular kind of telegram and save them in text file which is readable in nature. I have to do all of this using C++.
Do you suggest any other language for it or does anyone has any idea about doing this in C++?
Binary trace files are usually encoded in proprietary formats. And there are applications or profilers specifically built to parse them.
Unless you know the file format, the only way to decode it is through reverse engineering. And in most cases it's not worth the effort.
Try to find documentation about it. Or maybe an application or utility that loads the file and exports data that is easier to read.
In case you are speaking about .trc binary files from Teledyne Lecroy Oscilloscopes, I would suggest to any of the following libraries out there for that:
https://pypi.org/project/lecroyparser/
https://github.com/jneer/lecroy-reader
https://github.com/yetifrisstlama/readTrc
https://igit.ific.uv.es/ferhue/lecroyparser
I have an uploader in JSP, and through this I can upload several kinds of file. I need to perform a control (I think with regular expression, just a simple check on file extension) where the JSP engine could read the content of the file and understand if the file is an image or plain text file. I can accept only plain text (text or XML) and discard all the other kind of files. Could someone help me or suggest another way to do that?
As a very basic check you could verify the file extension with something like \.txt$, however this doesn't prevent people from uploading different filetypes with a .txt extension. You might be better off by checking the mimetype of the file uploaded, a JSP example can be found here.
I am using visual studio to develop a windows form application in c++ to detect certain anomalies and log it.
The log file that I am intending to create will be of a common format such as .txt. I do not want users of the computer to modify this file that is I want only my program to modify it( I want users to read this file not modify it).
Is there any way to achieve this??
if you want to hide the content from other users then encrypt the file or use a binary format that only your program will be able to understand.
As long as the file resides on a publicly accessible area in the file system, then other users will be able to access it.
You can put the file in a specific user's Documents area, which might go some way to protecting the file from other users of that machine, but not from administrators.
You could even set the file attributes to "hidden" or something along those lines, to further make it hard for people to find it. But a complete access block is difficult (if not impossible).
After all this, you can also use NirMH's method to ensure that even if someone finds and attempts to read the file, then the encryption should make it difficult to crack it open. A binary format can still be read with a hex editor, if someone is really keen to read your file.
Is there a way to determine if a file is a binary or text file using the the File Management functions or MFC?
In the File Management functions, GetFileType doesn't seem to distinguish between binary and text files. Same with the dwFileAttributes attribute here.
In MFC, I tried looking at CFile::GetStatus(), but the m_attribute doesn't say anything about whether files are binary or text.
Does anyone know a way to do this using one of these two libraries? Thank you.
(I'd like to know because I am trying to make a function that recursively goes through a directory. I rewrite the text files (using CStdioFile) and replace some words here and there... but it seems to screw up any images I have in the directory. I'd like to be able to copy the images too... but i need a way to distinguish between binary and text files so I can treat them differently.)
As far as I know, there's no simple API to do this, MFC or otherwise. However, there's a bunch of useful ideas in these similar questions:
How do I distinguish between 'binary' and 'text' files?
How to identify the file content as ASCII or binary
Apparently this supposed to be possible. For example opening and operating on a file with NOTEPAD, or HxD. But aren't they all text files...how would one specify which text editor to open the file and operate on the file with using the WINDOWS API. It is certainly not in "CreateFile".
Hopefully I'm understanding your question... The easiest way to do this is to launch the desired editor and pass the filename as an argument, rather than "invoking" the file (which will launch the default program associated with the file type).
For example, notepad.exe mytextfile.txt or gvim.exe mytextfile.txt.
If the editor is not on your %PATH%, you'll need to use a full path file name.
What are you trying to do, exactly? You could:
Maintain a list of editors that you expect to be installed and have entries for in the system's PATH (bad idea)
Have an editor/editors that you want to use, query the Windows registry to find the installation path of the editors (using RegGetValue), and launch the editor with CreateProcess) (a little better idea)
Query the registry to get the default editor for a given file type and then launch that editor using CreateProcess. (best idea)
But it all depends on what your goal is really.
Edit based on requirements
So, just so we're on the same page, from C++, you want to:
Take a command line parameter to your C++ application (filename)
Open that file in an arbitrary editor
Detect when the user has made changes to that file
Operate on the file contents
Is that correct?
If so, you could:
Use Boost libs to compute a CRC for the current data in the file
Launch an editor using one of the methods I initially described
Stick in a tight loop and sleep so you don't chew up resources while the initially computed CRC matches one calculated every iteration of the loop
Of course, there are all kinds of issues that you'd have to deal with (that's just a super simple way of describing the algorithm I might use), such as:
What happens if the user doesn't change the file?
What happens if the file isn't found?
I'm sure that there are a number of different methods of doing this, but this is the easiest method that I can think of at the moment (while still being able to be fairly certain of the changes).
Disclaimer: I haven't implemented something like this, so I might be completely off base ;)
Are you looking for the ShellExecute() or ShellExecuteEx() APIs on Windows? They'll launch whatever program is registered for a file (generally based on the filename extention).