get the path and filename of an object - praat

Is there a way within a praatscript to query the path and filename of an object.
I want to save a textgrid to the same file I opened (overwite it)
I was think of something like:
selectObject: n
type_name$ = selected$ ()
file_name$ = some_way_to_query_this..., n
type$ = extractWord$ (type_name$, "")
if type$ == "TextGrid"
runScript: "save.praat", file_name$
endif

No. Objects in Praat do not store information about their location on disk because most objects will never exist on disk at all. Objects are not files.
If you are reading an object from a file, and then want to store the object to the same location, then you should store that information elsewhere yourself.

This isn't an answer to your question but to the situation. Depending on how you open the textgrid, you could throw the filename into a string variable and then save to the same name.
file$ = "C:\Users\Me\Desktop\praat\example.TextGrid"
Read from file: file$
Set tier name: 1, "this"
Set tier name: 2, "that"
Save as text file: file$

This answer is quite late but it could be still useful to someone...
The file name, if it exists, can be shown with the Info command.
After selecting an object:
object_info$ = Info
file_name$ = extractLine$(object_info$, "Associated file: ")
writeInfo: file_name$

Related

i want to arrange the data as in text file but its format has been changed when i tried to get the file from directory and displayed in an app

I want to arrange the data as in a text file but its format has been changed when I tried to get the file from a directory and displayed it in an app the problem for me is it has no reference point at the line ending so I don't know how can I explode it Here is the file format:
This is how data should look
and this is how I am getting data:
This is how m getting the data now
one more thing from these lines I want to pick some data to be stored how can I pick data without reference points?
I mean as you see here:
PIDF***HEMP ZONE ULTRA THIN ROLLING PAPERS 1.25" 25CT~
we have * and ~ to explode and get the data in array format but how can we pick data when the data is like that:
B84921501625VSSE ALTO MENT 463405005397BX00090500360078000
"as I want to pick the name "ALTO MENT" 4, "63405005397
how can I pick that data?
Here is what I did till now:
public function read_confirmation(){
$cpath = public_path('confirmations\pending');
$c_allfiles = scandir($cpath);
$c_allfiles = array_diff(scandir($cpath), array('.', '..'));
foreach ($c_allfiles as $fname) {
$file= File::get(public_path('confirmations\pending/'.$fname));
return $file;}
}

Using one variable for multiple items data in descriptive programming

I know that with Descriptive programming you can do something like this:
Browser("StackOverflow").Page("StackOverflow").Link("text:=Go To Next Page ", "html tag:=A").Click
But is it possible to create some kind of string so I can assign more than one data value and pass it as single variable? I've tried many combinations using escape characters and I always get error.
For example in the case above, let's say I have more properties in the Page object, so I'd normally have to do something like this:
Browser("StackOverflow").Page("name:=StackOverflow", "html id:=PageID")...etc...
But I'd like to pass "name:=StackOverflow", "html id:=PageID" as a single variable, so when writing many objects I'd only have to write:
Browser(BrowserString).Page(PageString).WebEdit("name:=asdfgh")
And the first part would remain static, so if the parents' data needs to be modified I'd only have to modify two variables and not all the objects created in all libraries.
Is it possible?
If I was not clear enough please let me know.
Thank you in advance!
I think what you're looking for is UFT's Description object
This allows you finer grained control on the description since in descriptive programming all values are regular expressions but with Description you can turn the regular expression functionality off for a specific property.
Set desc = Description.Create()
desc("html tag").Value = "A"
desc("innertext").Value = "More information..."
desc("innertext").RegularExpression = False
Browser("Example Domain").Navigate "www.example.com"
Browser("Example Domain").Page("Example Domain").WebElement(desc).Click
If you want to represent this with plain string then it's a bit more of a problem, you can write a helper function but I'm not sure I would recommend it.
Function Desc(descString)
Set ret = Description.Create()
values = Split(descString, "::")
For Each value In values
keyVal = Split(value, ":=")
ret(keyVal(0)).Value = keyVal(1)
Next
Set Desc = ret
End Function
' Usage
Browser("StackOverflow").Page("StackOverflow").WebElement(Desc("html tag:=H2::innertext:=some text")).Click
Further reading about descriptive programming.
As an alternative to Motti's excellent answer, you could also Set a variable to match your initial descriptive object and then extend it as required:
Set myPage = Browser("StackOverflow").Page("name:=StackOverflow", "html id:=PageID")
after which you can then use
myPage.WebEdit("name:=asdfgh")
throughout the rest of the code, so long as the myPage object stays in scope...

Ruby String to access an object attribute

I have a text file (objects.txt) which contains Objects and its attributes.
The content of the file is something like:
Object.attribute = "data"
On a different file, I am Loading the objects.txt file and if I type:
puts object.attribute it prints out data
The issue comes when I am trying to access the object and/or the attribute with a string. What I am doing is:
var = "object" + "." + "access"
puts var
It prints out object.access and not the content of it "data".
I have already tried with instance_variable_get and it works, but I have to modify the object.txt and append an # at the beginning to make it an instance variable, but I cannot do this, because I am not the owner of the object.txt file.
As a workaround I can parse the object.txt file and get the data that I need but I don't want to do this, as I want take advantage of what is already there.
Any suggestions?
Yes, puts is correctly spitting out "object.access" because you are creating that string exactly.
In order to evaluate a string as if it were ruby code, you need to use eval()
eg:
var = "object" + "." + "access"
puts eval(var)
=> "data"
Be aware that doing this is quite dangerous if you are evaluating anything that potentially comes from another user.

How to get a file name from a list of files using link query

I am using linq query to get the filename from a list of file names. but I am getting null value. Is there anything wrong with the code??
var folderName = UserDetailsUtil.GetMemberPhotoPathFolderName(SessionData.UserID);
var fileName = SessionData.UserID;
var fileNames = Directory.GetFiles(Path.Combine(Server.MapPath("~/Content/Upload/MemberProfilePhotos/" + folderName)));
var actualFileName = fileNames.Where(x => x.StartsWith(fileName)).FirstOrDefault();
My image name will be with my userid. Total images in that particular folder comes into filenames. What i have to do is, I need to get the filename from the list of files
I assume that your file has an extension, so you need to find it without it, best by using the Path class:
var actualFileName = fileNames
.Where(fn => Path.GetFileNameWithoutExtension(fn) == fileName)
.FirstOrDefault();
Side-note acc. to "My image name will be with my userid". Then don't use StartsWith but ==, otherwise file 1 and 10 are equal. Changed that already in my code above.

How to insert and retrieve image in dbf file from vb6

I am writing a code in VB6 to save and retrieve an image in .dbf file, but i don't know what field type to take in dbf file. Can anyone suggest what field should i take in dbf file and what code should i write in VB6 ??
Thanks in advance..
I have done it in Memo Fields long ago. The code is in foxpro. See:
CREATE TABLE Abc.dbf Free (Filename c(50), Store M(4)) &&Create a table with FileName character field
*And Store as memo field
1.
Append blank &&to add a blank record
APPEND MEMO store from "D:\Shah.Jpg" overwrite
*This will copy the contents of the file. If Overwrite is ignored, and the memo has some contents,
*The contents of the file will be appended to it, which should be avoided.
REPLACE filename WITH "Shah.Jpg"
*Add as many files as you wish to other records.
Copy memo Store to "SomePhoto.jpg" && will copy to the default folder
*Or
Copy memo store to "c:\MyPhotos\Shah.JPG" &&You must save or know the extension of the file
2.
append blank
filedata=FILETOSTR("D:\Shah.JPG")
REPLACE store WITH filedata
STRTOFILE(store,"SomeFileName.JPG")
*OR
STRTOFILE(store,"c:\MyPhotos\SomeFileName.JPG")
It should solve your problem.
I have done it in Memo Fields long ago. The code is in foxpro. See:
CREATE TABLE Abc.dbf Free (Filename c(50), Store M(4))
*Create a table with FileName character field
*And Store as memo field
Method 1:
Append blank &&to add a blank record
APPEND MEMO store from "D:\Shah.Jpg" overwrite
*This will copy the contents of the file. If Overwrite is ignored, and the memo has some contents, *The contents of the file will be appended to it, which should be avoided.
REPLACE filename WITH "Shah.Jpg"
*Add as many files as you wish to other records.
Copy memo Store to "SomePhoto.jpg"
will copy to the default folder or
Copy memo store to "c:\MyPhotos\Shah.JPG"
*You must save or know the extension of the file
Method 2.
Append blank
filedata=FILETOSTR("D:\Shah.JPG")
REPLACE store WITH filedata
STRTOFILE(store,"SomeFileName.JPG")
*OR
STRTOFILE(store,"c:\MyPhotos\SomeFileName.JPG")
***It should solve your problem.
This is how I did it In Fox pro 9 it involves saving and retrieving image from MYSQL server.
1. First create table by the name:pictures with two fields image_id (int 10) and image(longBlob).
Now I wrote two function SaveImage RetriveImage"
CLOSE DATABASES
DO SaveImage WITH "C:\Users\Admin\Desktop\New folder (6)\rafay.jpg"
DO RetriveImage WITH "C:\KalimKhan2.jpg"
Function SaveImage
Parameters ImageName
&& Get image info
Create Cursor im (pic Blob)
Appen Blank
Overwrite`enter code here`
Append Memo pic From (ImageName) Overwrite
SQLDisconnect(0)
nconnect = SQLConnect('TEST_BOX','root')
If nconnect < 0
Wait Window 'Connection Failed!' Timeout 1
Return
Else
Wait Window 'Connected. ' Nowait
Endif
nresult = SQLExec(nconnect, [INSERT INTO pictures (image) VALUES (?pic) ] )
If nresult != 1
Aerror(laErr)
List Memory Like laErr To File c:\Error
error1 = .T.
=Aerror(x)
Wait Window " Query failed."
Endif
Return "good"
Function RetriveImage
Parameters ImageName
SQLDisconnect(0)
nconnect = SQLConnect('TEST_BOX','root')
If nconnect < 0
Wait Window 'Connection Failed!' Timeout 1
Return
Else
Wait Window 'Connected. ' Nowait
Endif
CursorSetProp("MapBinary",.T.,0)
nresult = SQLExec(nconnect, [Select * from pictures where image_id = 1 ],"ImageTemp" )
If nresult != 1
Aerror(laErr)
List Memory Like laErr To File c:\Error
error1 = .T.
=Aerror(x)
Wait Window " Query failed."
Endif
nBytes = Strtofile (ImageTemp.Image, (ImageName))

Resources