Octave. dlmread: unable to open file 'myfile.txt' - io

I have a txt file with data in form: 2104,3,399900 i_e int1,int2,int3 I have 50 rows in the same format.
Now I can want to put the data into variable, say, a.
I am using the the command :
a = csvread('ex1data2.txt');
%I have tried a = dlmread('ex1data2.txt'); it too does't work
it produces an error :
error: dlmread: unable to open file 'ex1data2.txt'.
I have added the path of the directory that have file to the octave search paths.
How can I read the text file?
Thanks.

Related

Extract tar.gz{some integer} in python

I am trying to extract a file name with this format--> filename.tar.gz10
I have tried mutpile wayd but for all of them, I get the error that is unknow format. it works fine for files ends with tar.gz00. I tried to change the name but still does not work.
Here are what I have tried,
import tarfile
file = tarfile.open('filename.tar.gz10')
file.extractall('./extracted_path')
file.close()
Another way is,
shutil.unpack_archive('./filename.tar.gz10', './extracted_path', 'tar.gz17')
Thanks for your help in advance.
This coule be because the archive was split into smaller chunks, on linux you could do so using the split -b command so one big file is actually multiple smaller ones now, and they are named like
file.tar.gz01
file.tar.gz02
file.tar.gz03
file.tar.gz04
etc...
you wont be able to decompress these file individually, so you have to concatenate them first into one file then decompress.
To verify whther it was split or not, run file {filename} and if does not recognize it as a gzip compressed archive then it is propably split (this is why you get unknown format error)
You can try to do the following:
from glob import glob
import os
path = '/path/to/' # location of your files
list_of_files = glob(path + '*.tar.gz*') # list all gzip files
bash_command = 'gzip -dk filename.tar.gz' + ' '.join(list_of_files) # create bash command to concatenate the files
os.system(bash_command)

How to define the condition of a corrupted file for audio file in Python

I am using Python 3.6, Jupyter notebook by connecting to a remote machine. I have a large dataset of mp3 files. I use FFmpeg (version is 2.8.14-0ubuntu0.16.04.1.) to convert mp3 files to wav format.
My code below goes over the file path list and if the file is mp3 it converts it to wav format and deletes the mp3 file. The code works but for a few files it stops and gives error. I opened those files and saw that they have no duration and each of them has size 600 looking at the terminal folder size column but it might be a coincidence. The error is file not found for 'temp_name.wav'.
I can see that these corrupted files are not able to be converted to wav. When I delete them manually and run the code again it works. But I have large datasets and cannot know which files are corrupted beforehand. Is there a way to make the code (before converting the file to wav) if the file is corrupted it deletes it and continues to next file. I just don`t know how to define the condition of a corrupted file or if the file cannot be converted to wav.
# npaths is the list of full file paths
for fpath in npaths:
if (fpath.endswith(".mp3")):
cdir=os.path.dirname(fpath) # extract the directory of file
os.chdir(cdir) # change the directory to cdir
filename=os.path.basename(fpath) # extract the filename from the path
os.system("ffmpeg -i {0} temp_name.wav".format(filename))
ofnamepath=os.path.splitext(fpath)[0] # filename without extension
temp_name=os.path.join(cdir, "temp_name.wav")
new_name = os.path.join(ofnamepath+'.wav')
os.rename(temp_name,new_name) # use original filename with wav ext
old_file = os.path.join(ofnamepath+'.mp3') # find and delete the mp3
os.remove(old_file)

FileNotFoundError even though file exist

when trying to open a file using wit open .. getting error that file doesn't exist.
I am trying to parse some txt files , when working localy it works with no issue, but the issue started when I am trying to connect to a network folder. the strange this is that is does see the file , but says its not found .
The Path I referring is '//10.8.4.49/Projects/QASA_BR_TCL_Env_7.2.250/Utils/BR_Env/Call Generator/results/Console_Logs/*' (this folder is full of txt files.
but I am still getting this error:
FileNotFoundError: [Errno 2] No such file or directory: 'Console_log_01-01-2019_08-17-56.txt'
as you see , it does see the needed file .
in order to get to this file I am parsing splitting the path the follwoing way :
readFile = name.split("/")[9].split("\\")[1]
because if I am looking on the list of my files I see them the following way :
['//10.8.4.49/Projects/QASA_BR_TCL_Env_7.2.250/Utils/BR_Env/Call Generator/results/Console_Logs\Console_log_01-01-2019_08-17-56.txt',
after splitting I am getting :
Console_log_01-01-2019_08-17-56.txt
and still it says the file is not found.
def main():
lines =0
path = '//10.8.4.49/Projects/QASA_BR_TCL_Env_7.2.250/Utils/BR_Env/Call Generator/results/Console_Logs/*'
files = glob.glob(path)
print ("files")
print ('\n')
print(files)
for name in glob.glob(path):
print (path)
readFile = name.split("/")[9].split("\\")[1]
print(readFile)
with open(readFile,"r") as file:
lines = file.readlines()
print (lines)
main()
files
['//10.8.4.49/Projects/QASA_BR_TCL_Env_7.2.250/Utils/BR_Env/Call Generator/results/Console_Logs\\Console_log_01-01-2019_08-17-56.txt', '//10.8.4.49/Projects/QASA_BR_TCL_Env_7.2.250/Utils/BR_Env/Call Generator/results/Console_Logs\\Console_log_01-01-2019_08-18-29.txt']
Traceback (most recent call last):
//10.8.4.49/Projects/QASA_BR_TCL_Env_7.2.250/Utils/BR_Env/Call Generator/results/Console_Logs/*
Console_log_01-01-2019_08-17-56.txt
File "C:/Users/markp/.PyCharmEdu2018.3/config/scratches/scratch_3.py", line 19, in <module>
main()
File "C:/Users/markp/.PyCharmEdu2018.3/config/scratches/scratch_3.py", line 16, in main
with open(readFile,"r") as file:
FileNotFoundError: [Errno 2] No such file or directory: 'Console_log_01-01-2019_08-17-56.txt'
Process finished with exit code 1
When you are looking for the file you are looking in the entire path, however when you are opening the file, you are referencing it as if it was in the local path, either change the current working directory with
os.chdir(path)
before opening the file, or in the open statement use
open(os.path.join(path,filename))
I recommend the first approach if you have to open only one file in your program and second if you open multiple files at multiple directories.
In future better format your questions, stack overflow has multiple tools, use them, also you can see how your text looks, make sure to have a look at it before posting. Use the code brackets for your code, that will help whoever is trying to answer.

ParaView get file path

I am opening some VTU files from Directory X and there are other output files in that directory (for example log.txt) that I want to open via a plugin. If I do a os.getcwd() I end up in ParaViews installation directory. What I want is the directory of the VTU files I loaded BEFORE applying the plugin... So basically the start Point of the Pipline.
You could do something like this to get the reader
myreader = FindSource('MyReader')
then get the file name via the FileName attribute
myreader.FileName

How to convert BCP exported .xls file to actual Excel format file?

I have a batch file with the statement below. The export works fine and results are in the file Corp.xls. However, when I try to open this file, I get a warning 'The file you are trying to open is in a different format that that specified by the file extenion ..........
When I open the file and try to 'Save As', I find that it is in Text-tab delimted format.
Is there any way to convert such a file to excel without having to open the file - i.e from the batch file ?
Note: The batch file is very comples. Given below is just a modified snippet.
BCP "exec DBname.dbo.sp_abc '201503' " queryout "\\ABC\3_MAR\Corp.xls" -T -c -S SCC-SLDB

Resources