473,387 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How do you get a filename from a handle/resource?

Hi all,

Does anyone know how you can get a filename if all you've got is the
resource (e.g. returned by fopen())?

The reason I ask is that I'd like to use tmpfile() to create a temporary
file (because then it will be automatically deleted should my script
abruptly terminate.) Once I've written my data to this file, I then
need to pass the filename on to an external command, but I can't see any
way to find out what the temporary file is called.

I've tried using fstat(), but this returns everything except the filename.

Any ideas?

Thanks,
Adam.
Oct 9 '08 #1
3 16921
Adam Nielsen schreef:
Does anyone know how you can get a filename if all you've got is the
resource (e.g. returned by fopen())?
You can't, unless you write a wrapper which stores the file name.
The reason I ask is that I'd like to use tmpfile() to create a temporary
file (because then it will be automatically deleted should my script
abruptly terminate.)
It depends on what you mean by "abruptly terminate". When your script
crashes or manually interrupted, the temporary file won't be deleted.
JW
Oct 9 '08 #2
Adam Nielsen escribió:
Does anyone know how you can get a filename if all you've got is the
resource (e.g. returned by fopen())?

The reason I ask is that I'd like to use tmpfile() to create a temporary
file (because then it will be automatically deleted should my script
abruptly terminate.) Once I've written my data to this file, I then
need to pass the filename on to an external command, but I can't see any
way to find out what the temporary file is called.

I've tried using fstat(), but this returns everything except the filename.
Use tempnam() instead:

http://es2.php.net/manual/en/function.tempnam.php
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Oct 9 '08 #3
Adam Nielsen wrote:
Hi all,

Does anyone know how you can get a filename if all you've got is the
resource (e.g. returned by fopen())?

The reason I ask is that I'd like to use tmpfile() to create a temporary
file (because then it will be automatically deleted should my script
abruptly terminate.) Once I've written my data to this file, I then
need to pass the filename on to an external command, but I can't see any
way to find out what the temporary file is called.

I've tried using fstat(), but this returns everything except the filename.

Any ideas?

Thanks,
Adam.
You can't. But then the file will be deleted when you fclose() it - and
you should close a file you have open for writing before passing it off
to another program, anyway.

Rather, use tempname() to get a unique name, then open it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Oct 9 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Terry | last post by:
There are a number of things about using unmanaged resources in Windows Forms programming that is unclear to me. In C++, if you loaded an icon resource using "ExtractIcon()", the resource was...
1
by: Fei Yuan | last post by:
Please forgive me re-posting this question since I wasn't clear in my original post. --------> Starting an external process needs to pass it a ProcessStartInfo() object. ProcessStartInfo has a...
1
by: Andrew Roesch | last post by:
Hello all, I believe I have a tough one today. I'm trying to load a color cursor from an embedded resource in C# and am having quite a bit of trouble doing it. Let me tell what I have found out...
0
by: Andrew Roesch | last post by:
If anyone has any ideas, or a better forum to post in, please let me know. I'm trying to load a color cursor from an embedded resource in C# and am having quite a bit of trouble doing it. Let me...
2
by: Joe Thompson | last post by:
Hi, I am trying to use PlaySound in a VC++.net Windows app (VS 2003). I can use it to play a file but now I want to play it from a resource. I have two questions: How do I add a wav file to...
6
by: farseer | last post by:
Hi, I created a new resouce ("app.resx") in my project and added an icon to this resource with name "IL_ICON". I would like to use this resource in some unmanaged code, in particular, with the...
0
by: Mythran | last post by:
I wrote some code that is supposed to enumerate through the specified file's win32 resources and return a string-array of all icon names. When it runs, it returns a string-array with a bunch of...
5
by: Paul Cheetham | last post by:
Hi, I have some custom colour cursors which I have added to my c# project, and set them to be compiled as "Embedded Resource" It seems impossible to load a colour cursor using the standard...
0
by: jinnareddy | last post by:
Hi, I'm unable to download a file that is having a 2-byte char in its name (e.g.テ) using force download option. Though, am able to download file names involving ASCII chars. I have tried URL...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.