Can I open a file from specific offset1 to specific offset 2 - gzip

In c++ enviroment, How can I open a file for the sake of merge it to a gzip file, I need to
add part of the file to gzip file, can any body help? thank first!

open it as usual, and then fseek() it.

Related

custom file open with custom application only

I am working on vb.net application where I wanted to create and read a file. File will have specific extension for ex. .abcb the way I want my application to work is:
can create a file with .abcd extension
should read .abcd files only(and also application created files only so altered extension shouldn't be working)
.abcd files should show some garbage data when open in any other application(ex. word, notepad any image viewer etc.)
Now my application does 1,2(partly) step, i.e. it creates a file and load data also, it reads .abcd files only(not the altered files)
but created file can be read by other software's also.I tried searching a lot but have not found anything and don't know where to start.
Any help is appreciated!
if you don't want other programs to be able to read the content of your file then your going to have to mask it in some way, which is usually done with encryption.
assuming your not too worried about the key being compromised, the easiest way to accomplish this would be to generate a key with something like System.Security.Cryptography and use that key to encyrpt everything you send to the file and everything you read from it.
as for making your own file extension, you can make the extension of a file whatever you want when you make it:
Dim fs As FileStream = File.Create("/path/to/file/filename" & ".abcd")
the only thing that the extension does is tell the OS what progam to use when opening a file by default, which will probably be notepad since your making your own extension

Can you write to a file without knowing its complete file path?

In a program I am creating I want to write to a txt file. I know how to do this, however the method I use requires me to know the entire file path of the target file. Is there a way to do this without knowing the entire file path, or, if possible, write to a file located in the project resources?
There are several possible solutions:
Write the contents of the file to MemoryStream and when you know the path of the file write the stream to the file.
Write the file contents to a temporary file, and when you know the path of the file, copy the temporary file to the same path

Method to inspect first 4 bytes and rename file extension

I have a large batch of assorted files, all missing their file extension.
I'm currently using Windows 7 Pro. I am able to "open with" and experiment to determine what application opens these files, and rename manually to suit.
However I would like some method to identify the correct file type (typically PDF, others include JPG, HTML, DOC, XLS and PPT), and batch rename to add the appropriate file extension.
I am able to open some files with notepad and review the first four bytes, which in some cases shows "%PDF".
I figure a small script would be able to inspect these bytes, and rename as appropriate. However not all files give such an easy method. HTML, JPG, DOC etc do not appear to give such an easy identifier.
This Powershell method appears to be close: https://superuser.com/questions/186942/renaming-multiple-file-extensions-based-on-a-condition
Difficulty here is focusing the method to work on file types with no extension; and then what to do with the files that don't have the first four bytes identifier?
Appreciate any help!!
EDIT: Solution using TriD seen here: http://mark0.net/soft-trid-e.html
And recursive method using Powershell to execute TriD here: http://mark0.net/forum/index.php?topic=550.0
You could probably save some time by getting a file utility for Windows (see What is the equivalent to the Linux File command for windows?) and then writing a simple script that maps from file type to extension.
EDIT: Looks like the TriD utility that's mentioned on that page can do what you want out of the box; see the -ae and -ce options)
Use python3.
import os,re
fldrPth = "path/to/folder" # relative to My Documents
os.chdir(fldrPth)
for i in os.listdir():
with open(i,'r') as doc:
st = doc.read(4)
os.rename(i,i+'.'+re.search(r'\w+',st).group())
Hopefully this would work.
I don't have test files to check the code. Take a backup and then run it and let me know if it works.

Get overridden file data?

I have a script file. Unfortunately I've overridden it with some other data. I need the old data. crtl+Z is not working.
How do I recover it?
unfortunately some editors are not supporting of crtl + Z so only not able to recover the data..
are you using file versioning? what OS, what version?
What is the File structure? NTFS?
if you overwrite a file in NTFS it tends to delete the first file and put in the second, not systematically destroy the file (so you can recover the file with an undelete utility.
first, rename the current file, then open an undelete utility (you don't want to download anything to this computer as you may overwrite the file.)
run it from a memory stick.
the safest thing to do if it's critical is to image the device off to a donor scratch media and work from there.

use Archive Utility.app from command line (or with applescript)

I would like to use Archive Utility.app in an app I'm writing to compress one or more files.
Doing (from the command line):
/System/Library/CoreServices/Archive\ Utility.app/Contents/MacOS/Archive\ Utility file_to_zip
Does work but it creates a cpgz file, I could live with that (even though .zip would be better) but the main problem is that I am not able to compress 2 files into 1 archive:
/System/Library/CoreServices/Archive\ Utility.app/Contents/MacOS/Archive\ Utility ~/foo/a.txt ~/bar/b.txt
The above command will create 2 archives (~/foo/a.txt.cpgz and ~/bar/b.txt.cpgz).
I cannot get this to do what I want either:
open -a /System/Library/CoreServices/Archive\ Utility.app --args xxxx
I'd rather not use the zip command because the files that are to be compressed are rather large so it would be neat to have the built in progress bar.
Or, could I use Archive Utility programmatically?
Thanks.
Archive Utility.app uses the following to create its zip archives:
ditto -c -k --sequesterRsrc --keepParent Product.app Product.app.zip
Archive Utility.app isn't scriptable.
The -dd/--display-dots option will cause the command-line zip utility to displays progress dots when compressing. You could parse the output of zip for your progress bar. zip will also display dots if it takes more than five seconds to scan and open files.
Better would be to integrate a compression library, such as zlib or libbzip2. Both of those let you compress a portion of the data at a time. You'll need to handle progress bar updates, which you can do after compressing each block of data.
How about Automator? The "Create Archive" action would work.
I have used Archive Utility to decompress files from Applescripts:
tell application "Archive Utility" to open filePath
However, this only tells Archive Utility to start decompressing. It will complete in its own time and the applescript will continue to execute without waiting for the decompression to finish. Archive Utility will not tell the applescript when it is done.
You can use the above line if Archive Utility is already running. It will add the new file to its queue and decompress when ready.
Also, Archive Utility's preferences will control how it accomplishes the goal. For example: it might decompress to a different folder or delete the original. You can run it as a program and change the preferences if that helps.
I have not used this to get Archive Utility to compress files.