Python: multiple files containing JPEGs, copy and paste all file contents into one file - append

I have a list with several .rtf files ("file_withPath") containing PNG or JPG images inside them. I would like to copy the file contents and paste all images in a newly created file called "package.rtf". Unfortunately, with the several methods I have used to do this problem, it keeps rewriting the output file each time through the loop. I only see the final PNG that was copied and pasted instead of all of them pasted sequentially.
Code:
list1.append(file_withPath)
for item in list1:
outfile = open(r"C:\Users\3\Desktop\collection\package.rtf", "w")
shutil.copyfileobj(open(item, "r"), outfile)

Related

Combine data from multiple .log files and reading them without creating new .txt file in MATLAB

At the moment I have working code that can read multiple .log files and create a giant .txt file which contains all their data. Then I simply read the giant .txt file. However, this code is inefficient because it involves writing a new .txt file every time I want to run the script.
Does someone know how to simplify this so that it doesn't write a new .txt file every time? Ideally by creating a 'virtual' .txt file?
files=dir('IndividualFiles.*.log');
fileout='GIANT.txt';
fout=fopen(fileout,'w');
for cntfiles=1:length(files)
fin=fopen(files(cntfiles).name);
temp = fread(fin,'uint8');
fwrite(fout,temp,'uint8');
fprintf(fout,'\n');
fclose(fin);
end
fclose(fout);
filename = 'C:\Users\myname\Desktop\Learning Documents\myfolder\GIANT.txt';

How can i convert .txt to .flv?

I have a .flv video and want to copy it. l modified the suffix of the video. l opened this file using sublime and copy data. Then I created new .txt file, pasted data, saved it. Finally, I modified the new text file to .flv. It cannot work. I tried to make you understand my problem. Can somebody tell me the reason?

Renaming files in Matlab - movefile is creating folders instead of files

The current working directory contains a folder called 'dynamics_sorted' which contains 300 subfolders ('001', '002', etc), each of which contains some files, but only a single nifti (.nii) file.
The single nifti file from each of the numbered subfolders should be moved into 'dynamics_sorted_NIFTI' which is in the current working directory.
In the process, each nifti file should be renamed with the number of its parent folder.
The syntax for movefile suggests that when the arguments are both filenames then the file is renamed
http://uk.mathworks.com/help/matlab/ref/movefile.html#zmw57dd0e528520
for Ticker = 1:300;
FindNiftiFile = ['dynamics_sorted/',num2str(Ticker,'%03.0f'),'/*.nii'];
PutNiftiFile = ['dynamics_sorted_NIFTI/',num2str(Ticker,'%03.0f'),'.nii'];
movefile(FindNiftiFile,PutNiftiFile);
end
But this code does not rename the files, instead it keeps the filenames but places them into numbered folders.
Any advice as to where the error is?
I've found the answer - it's because of the wildcard used to find the source file. I'm guessing this leads Matlab to assume the source is not a single file, even when the wildcard is such that only a single file is eligible.

AND operation for textfiles in MATLAB

I've 3 .txt files. I want to perform and operation to these 3 text files and to save the output in a new text file.
fid = fopen(AND('a.txt','b.txt','c.txt'));
will this work as per my requirements? but i want to save in a new text file, how can i go for it?
For example my a.txt file contents are
DSC01605.bmp
Hampi8.bmp
DSC01633.bmp
DSC01198.bmp
DSC01619.bmp
similarly some images are present in b.txt file, and hence in c.txt file. I just want to get similar image names out of those files which are saved in above text files, and want to save in a separate new text file.

How to clear/delete contents of .txt file in matlab

How can I either delete the contents of a .txt file so that it becomes a blank file or it deletes the file altogether? I'm reading in from the .txt file and if I don't delete the contents from the previous time it ran, it will omit results that I want to account for.
Suppose your file is named to_be_deleted.txt, you can simply use the following command to delete the file altogether:
delete 'to_be_deleted.txt';
On the other hand, if you simply want to clear it's contents, just open it using fopen with the write attribute as follows:
fopen('to_be_deleted.txt','w');