PDA

View Full Version : Edit a NotePad file?



mburt
09-25-2006, 08:31 PM
I'm assuming I can do this with AJAX (most likely not). But how exactly can I edit a notepad file (add stuff to it)? I don't want to do this on my server, just on my pc.

Twey
09-25-2006, 09:04 PM
Without ActiveX or Java, you can't.

mburt
09-25-2006, 09:13 PM
Thanks. So how can I use Java to do this?

djr33
09-26-2006, 08:44 AM
Or php...

codeexploiter
09-26-2006, 09:28 AM
import java.io.*;

class one
{
public static void main()
{
try {
BufferedWriter out = new BufferedWriter(new FileWriter("t.txt", true));
out.write("aString");
out.close();
}
catch (IOException e) {}
}
}


The above code should write into a txt file though not tested.

jscheuer1
09-26-2006, 10:10 AM
Depending upon how and when you want to add stuff to a notepad file and where you want to get that stuff from, batch programming might be your best bet.

By the way, a notepad file is only an ordinary text file.

This batch file:


@echo off
echo fadeimages=[ > test_it.js
for %%p in (*.jpg, *.gif, *.png) do echo 'file://localhost/C:/internet/project/files/%%p', >>test_it.js
echo 'end'] >>test_it.js

Call it - make_js.bat - will create or overwrite a javascript (an ordinary text file) file that when linked to a given HTML page will then create an array of images (with one extra entry that can later be trimmed using javascript) from the directory using the localhost absolute path (red) of one's choosing.

djr33
09-26-2006, 11:49 AM
Actually, about php-- if you're talking about a local file, it won't work. As Twey said, ActiveX and Java (and I believe flash, if it has special permissions and complex code) are the only ways to modify an existing text file on your harddrive. I misread the original post, sorry.
PHP (as well as other server side languages-- CGI/ASP/etc.) can, though, on the server (or just output to the user).

Twey
09-26-2006, 03:25 PM
import java.io.*;

class one
{
public static void main(String[] args)
{
try {
BufferedWriter out = new BufferedWriter(new FileWriter("t.txt", true));
out.write("aString");
out.close();
}
catch (IOException e) {}
}
}The signature for main is
public static void main(String[])If the signature isn't matched, main won't be called.

Of course, if you're just seeking to automate the creation of a large text file, John's batch file idea will work fine.

mburt
09-26-2006, 07:48 PM
I knew about the batch file way, but I was trying to mix it into a webpage, and that I'm aware of, bat files can't be encorperated into webpages :)

mburt
09-26-2006, 07:51 PM
I want to get input from the user too, then add to a .txt file

jscheuer1
09-27-2006, 04:56 AM
IE only - With the security settings I have, I had to click one alert box to allow this:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
// Instantiate a File System ActiveX Object:
var fso = new ActiveXObject("Scripting.FileSystemObject");
// Invoke the method:
var a = fso.CreateTextFile("c:\\testfile.txt", true);
// Do something with it:
a.WriteLine("This is a test.");
// Close the connection:
a.Close();
</script>
</head>
<body>

</body>
</html>

It is probably possible to set IE to allow this locally without a warning though.

BLiZZaRD
09-27-2006, 05:22 AM
But how exactly can I edit a notepad file (add stuff to it)? I don't want to do this on my server, just on my pc.

To which the NB response comes in as ... "why don't you just open your .txt file in notepad on your PC and edit it. Remember to save on close."

:D

jscheuer1
09-27-2006, 07:32 AM
To which the NB response comes in as ... "why don't you just open your .txt file in notepad on your PC and edit it. Remember to save on close."

:D

How about edlin and DOS EDIT? :D

BLiZZaRD
09-27-2006, 07:36 AM
don't know edlin.. LOL **runs off to google**


<edit>
OHHHHHHH ROTF (http://www.xmission.com/~comphope/edlin.htm) It is STILL avaliable in XP!!! Wow!

djr33
09-27-2006, 08:17 AM
Why are you storing it on the user's computer?
...cookie, perhaps? That's easy enough.
You might just be better off storing it on the server... what's your goal?
You said it's for you personally... but there are easier/better ways than using webpages if you're not using it on a server.

mburt
09-27-2006, 10:22 AM
Actually, I'm feeding data onto my site getting variables from a notepad file, and I want the other admin to be able to edit that notepad file accordingly. I might have a variable for players' stats:

p1p=a string goes here
P2p=another string


I eventually ended up with so many variables, it got impossible to read. So I decided to try to make a program to help the user do it easier.

djr33
09-27-2006, 10:31 AM
REALLY not worth it.
Use a database and be done with it. Easy. (Or at least easier)

Even just use a text file on the server.... this is just too much work for something that can be done simply another way.

Is there any particular reason it must be done like this?


I suppose, if needed, you could use php to upload the file, interpret the data, then, if you wanted to edit it, output as a .txt, then edit that, then upload.... repeat.

mburt
10-01-2006, 01:46 AM
Problem 1: I've tried to get a database to work three times and have had no success.
Problem 2: I need to be able to do this right away, there's people that want to be able to edit it

jscheuer1
10-01-2006, 01:59 AM
If you have PHP, look at this:

http://www.phpxplorer.org/phpXplorer/webIndex.php

looks promising. I have no experience with it though so, I am not recommending it, just mentioning it. It's free.