Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

saving txt to a directory and not to a hard drive

Status
Not open for further replies.

nnn000555

Programmer
Jan 30, 2011
26
CA
Is it possible, and, if yes, then, how do you save a txt file to a directory and not to a hard drive? What is an example of a directory path to the destination?
 
That makes absolutely no sense. A directory or folder exists on a hard drive somewhere. At the most a USB drive could hold the directory, but its still a hard drive.

Perhaps you could explain a bit more what you mean.




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Hi

Phil said:
A directory or folder exists on a hard drive somewhere.
[tt][blue][small][ignore][off-topic][/ignore][/small][/blue][/tt]
Unless it is stored on a RAM disk. But JavaScript would be among the lasts of finding this out.
[tt][blue][small][ignore][/off-topic][/ignore][/small][/blue][/tt]

However, I agree,
Phil said:
That makes absolutely no sense.

Feherke.
 
I will try to elaborate. I have used a command \\servername\sharenamefilename.txt\ to create a file on my computer, on C drive, called servernamesharnamefilename.txt. The file is created and information is appended to file. But I tried to download the file online onto a third party server. Probably, the file is saved in the server C drive. But I don't want it saved there. I want it saved in the home directory of my user allocated space. How do I do that? How do I modify the command? It must be saved in the same current directory for that purpose?
 
I'm having a difficult time following your response. it may just help to list out the rules though.

1. the browser will not automatically save files to the user's computer to a location that you, the developer/server, specifies.
2. the client/user cannot tell the server where to store the file.
3. web servers usually run under very restrictive permissions. typically the process running the website only has access to the root directory of the site. it would not have access the to other directories (c:\, program files, my documents, etc)

In both cases the server shouldn't care where/what the client does with the downloaded file. and the client shouldn't care how the server manages the uploaded file. that's one of the key features of client/server environments.

now what you do have access to from the both the client and server are cookies. These can be used to store pieces of data as a way to hold state between requests. you shouldn't put anything sensitive into the cookie. typically cookies are used to hold user preferences. persist logins between session etc.

from what I read it sounds like you have an architectural problem. Not a coding problem.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
It is hard to tell, if this architectural problem could be solved by code for instance, I have been researching, and found a command dirname(path) it could be used in javascript or php. I prefer to use in javascript. Do you know anything about this command and how to use. A tutorial on how it is used would be helpful. thanks.
What the command does is it returns the path of what is entered in the brackets in dirname(path).
 
function dirname(path) {
return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, '');;
this is the command but I have no clue what to do with it.
 
function dirname(path) { return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, '');
 
the theory behind the command dinrname(path) is here

comment: # Where $path_separator is / for Unix, \ for Windows,

dirname($path) . $path_separator . basename($path);
 
JS & php are independent of one another. they can both be used to design a website, but js & php do not directly communicate with on another.

the function above is using regex to replace characters in a string. It has nothing to do with file IO. granted you could use this to change a string that contains a file path. but the actual file operations are independent of the regex operation.

solving poor architectural design decisions with code usually leads to disaster. It's better to solve the root problem, then tend to the symptoms. By designing the system that works with the enviornment (in this case web) rather than against it your system will be easier to build, understand and maintain.

In this case, if I understand your scenario. you want the server to tell the client where to save the file, or vice versa. In either case the web doesn't allow this.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
<script type="text/javascript">
var c=0;
var file = "\\my-file.txt"
function addToFile() {
var fs = new ActiveXObject("Scripting.FileSystemObject")
var ts = fs.OpenTextFile(file,8,true,-2)
</script>
Allows me to save into the my-file.txt information. 8 and -2 allow the file to not refresh. So, basically, I can store information in that file permanently. There is one problem. It saves my-file.txt in C drive. Eventhough, you might be working on user drive, which is completely different from c. So, I need to find out what is the path of the my-file.txt in user terms on a web server. It is a home directory of my user.
My solution is to find out what is the path of my-file.txt and put something like
var file = "g:/myfolder/myfiles/my-file.txt"
But for that I need to find out the path. So can I use dirname() or basename() to find out the path? Thanks.
 
I found out, that dirname returns the directory of the path, except that you have to enter the path yourself, and all it does is it takes away the file.txt at the end. I need something like that, except I need to find out the path, knowing the file.txt. May be there are commands in unix that are similar to dirname(path) in javascript? I would need to use them in javascript environment.
 
or maybe there are commands in unix, that simply place the file in the same directory, instead of putting them in c on line
var file = \\my-file.txt (use something like .\my-file.txt.. or anything else like that in unix?)
 
What is an equivalent of unix pwd in javascript. In Java its getCannonicalPath(), can I use that in Javascript?
 
If I have a command
ts.Write(getCannonicalPath());
it runs and compiles.

But I don't see the path.
There must be a different spelling. What is it? Help?
 
Here is an example on how to create a file, but the getCanonicalPath does not give you any results. What can you use to find the path of the file? or pwd?
<html>
<head>
</head>
<body>
<script type="text/javascript">
var c=0;
var file = "\\folder\my-path.txt"
function addToFile() {
var fs = new ActiveXObject("Scripting.FileSystemObject")
var ts = fs.OpenTextFile(file,8,true,-2)
/* var t = document.getElementById("txt").value
*/
alert("Saving... ")
c++;
ts.WriteBlankLines(3) ;
// Write a line.
ts.Write(c);
var path= ts.getCanonicalPath('foldermy-path.txt')
ts.Write(path)
ts.Close()
ts=fs=null
}
</script>
<form action="" name = "frm">
Click here:
<input type="button" onclick="addToFile()" value="Save Information To Submit" />
</form>
</body>
</html>
 
I think I get what you want. You want to get the real path in the remote server or machine of a file you are accessing through a network share. That is the PC that is opening the website, is just sort of a gateway if you will to a shred resource on the network.

[Website]->[PC]->[local network]->[network server]->[folder-path]-[file]


So this:
var file = "\\folder\my-path.txt"

Would be more accurately described as:
Code:
var file = "\\local_network_server\serverfolder\my-file.txt"
And you want the actual path of the file in the remote server?

I don't think you can get that, nor would you need to.

As the actual path could be something like: C:\users\documents\soemotherfolder\sharedfiles\my-file.txt and because you can't access that path directly anyway.

Having that is of no use to you, unless you wanted to recreate that path in the local machine. But that is not something a website would ever need to do. As was said above, the website should not care where the user stores the file.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
->[network server]->[folder-path]-[file]
Actually, that's the path that I would like to recreate.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top