/ Forside/ Teknologi / Udvikling / ASP / Spørgsmål
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
ASP
#NavnPoint
smorch 9259
Harlekin 1866
molokyle 1040
Steffanst.. 758
gandalf 657
smilly 564
gibson 560
cumano 530
MouseKeep.. 480
10  Random 410
Copy, Delete, Create, Move....
Fra : crha
Vist : 627 gange
100 point
Dato : 27-02-03 21:10

Hejsa

Jeg kunne godt tænke mig at få at vide hvordan man viser, kopierer, flytter, opretter, redigerer, sletter, omdøber og viser information om filer der ligger i en given mappe.

Jeg vil meget gerne have koderne og ikke et link til et eller andet script jeg alligevel ikke kan fortolke :)

Håber nogen kan hjælpe.

Mvh.
Casper

 
 
Kommentar
Fra : sjagget2003


Dato : 28-02-03 11:15

Kan du ikke lige uddybe hvilket styresystem du køre med og hvad du mener med et script, da det du skriver nemt kan gøres med et klik med musen....

Kommentar
Fra : crha


Dato : 28-02-03 15:05

Det skal være et ASP script som kan bruges til at administrere mit webhotel, men jeg vil gerne selv programmere et sådan script, problemet er bare jeg ikke ved hvordan.
Det er vist også ret ligegyldigt hvilket styresystem der bliver brugt, da det er et ASP script der skal udføre opgaven. Or am I wrong!?

Kommentar
Fra : sjagget2003


Dato : 01-03-03 14:38

Sorry!! misforstod dit spørgsmål, ASP scripts er ikke lige min stærke side, håber andre kan hjælpe dig...

Kommentar
Fra : crha


Dato : 01-03-03 16:16

Det gør da ikke noget :)

Kommentar
Fra : smorch


Dato : 06-03-03 07:06

Scripting Runtime Library

Working with Files
There are two major categories of file manipulation:

Creating, adding, or removing data, and reading files
Moving, copying, and deleting files
Creating Files
There are three ways to create an empty text file (sometimes referred to as a "text stream").

The first way is to use the CreateTextFile method. The following example demonstrates how to create a text file using the CreateTextFileMethod method.

[VBScript]
Dim fso, f1
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.CreateTextFile("c:\testfile.txt", True)
[JScript]
var fso, f1;
fso = new ActiveXObject("Scripting.FileSystemObject");
f1 = fso.CreateTextFile("c:\\testfile.txt", true);
The second way to create a text file is to use the OpenTextFile method of the FileSystemObject object with the ForWriting flag set.

[VBScript]
Dim fso, ts
Const ForWriting = 2
Set fso = CreateObject("Scripting. FileSystemObject")
Set ts = fso.OpenTextFile("c:\test.txt", ForWriting, True)
[JScript]
var fso, ts;
var ForWriting= 2;
fso = new ActiveXObject("Scripting.FileSystemObject");
ts = fso.OpenTextFile("c:\\test.txt", ForWriting, true);
A third way to create a text file is to use the OpenAsTextStream method with the ForWriting flag set.

[VBScript]
Dim fso, f1, ts
Const ForWriting = 2
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CreateTextFile ("c:\test1.txt")
Set f1 = fso.GetFile("c:\test1.txt")
Set ts = f1.OpenAsTextStream(ForWriting, True)
[JScript]
var fso, f1, ts;
var ForWriting = 2;
fso = new ActiveXObject("Scripting.FileSystemObject");
fso.CreateTextFile ("c:\\test1.txt");
f1 = fso.GetFile("c:\\test1.txt");
ts = f1.OpenAsTextStream(ForWriting, true);
Adding Data to the File
Once the text file is created, add data to the file using the following three steps:

Open the text file.

Write the data.

Close the file.

To open an existing file, use either the OpenTextFile method of the FileSystemObject object or the OpenAsTextStream method of the File object.

To write data to the open text file, use the Write, WriteLine, or WriteBlankLines methods of the TextStream object, according to the tasks outlined in the following table.

Task Method
Write data to an open text file without a trailing newline character. Write
Write data to an open text file with a trailing newline character. WriteLine
Write one or more blank lines to an open text file. WriteBlankLines

To close an open file, use the Close method of the TextStream object.

Note The newline character contains a character or characters (depending on the operating system) to advance the cursor to the beginning of the next line (carriage return/line feed). Be aware that the end of some strings may already have such nonprinting characters.
The following example demonstrates how to open a file, use all three write methods to add data to the file, and then close the file:

[VBScript]
Sub CreateFile()
Dim fso, tf
Set fso = CreateObject("Scripting.FileSystemObject")
Set tf = fso.CreateTextFile("c:\testfile.txt", True)
' Write a line with a newline character.
tf.WriteLine("Testing 1, 2, 3.")
' Write three newline characters to the file.
tf.WriteBlankLines(3)
' Write a line.
tf.Write ("This is a test.")
tf.Close
End Sub
[JScript]
function CreateFile()
{
var fso, tf;
fso = new ActiveXObject("Scripting.FileSystemObject");
tf = fso.CreateTextFile("c:\\testfile.txt", true);
// Write a line with a newline character.
tf.WriteLine("Testing 1, 2, 3.") ;
// Write three newline characters to the file.
tf.WriteBlankLines(3) ;
// Write a line.
tf.Write ("This is a test.");
tf.Close();
}
Reading Files
To read data from a text file, use the Read, ReadLine, or ReadAll method of the TextStream object. The following table describes which method to use for various tasks.

Task Method
Read a specified number of characters from a file. Read
Read an entire line (up to, but not including, the newline character). ReadLine
Read the entire contents of a text file. ReadAll

If you use the Read or ReadLine method and want to skip to a particular portion of data, use the Skip or SkipLine method. The resulting text of the read methods is stored in a string which can be displayed in a control, parsed by string functions (such as Left, Right, and Mid), concatenated, and so forth.

The following example demonstrates how to open a file, write to it, and then read from it:

[VBScript]
Sub ReadFiles
Dim fso, f1, ts, s
Const ForReading = 1
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.CreateTextFile("c:\testfile.txt", True)
' Write a line.
Response.Write "Writing file <br>"
f1.WriteLine "Hello World"
f1.WriteBlankLines(1)
f1.Close
' Read the contents of the file.
Response.Write "Reading file <br>"
Set ts = fso.OpenTextFile("c:\testfile.txt", ForReading)
s = ts.ReadLine
Response.Write "File contents = '" & s & "'"
ts.Close
End Sub
[JScript]
function ReadFiles()
{
var fso, f1, ts, s;
var ForReading = 1;
fso = new ActiveXObject("Scripting.FileSystemObject");
f1 = fso.CreateTextFile("c:\\testfile.txt", true);
// Write a line.
Response.Write("Writing file <br>");
f1.WriteLine("Hello World");
f1.WriteBlankLines(1);
f1.Close();
// Read the contents of the file.
Response.Write("Reading file <br>");
ts = fso.OpenTextFile("c:\\testfile.txt", ForReading);
s = ts.ReadLine();
Response.Write("File contents = '" + s + "'");
ts.Close();
}
Moving, Copying, and Deleting Files
The FSO object model has two methods each for moving, copying, and deleting files, as described in the following table.

Task Method
Move a file File.Move or FileSystemObject.MoveFile
Copy a file File.Copy or FileSystemObject.CopyFile
Delete a file File.Delete or FileSystemObject.DeleteFile

The following example creates a text file in the root directory of drive C, writes some information to it, moves it to a directory called \tmp, makes a copy of it in a directory called \temp, then deletes the copies from both directories.

To run the following example, create directories named \tmp and \temp in the root directory of drive C:

[VBScript]
Sub ManipFiles
Dim fso, f1, f2, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.CreateTextFile("c:\testfile.txt", True)
Response.Write "Writing file <br>"
' Write a line.
f1.Write ("This is a test.")
' Close the file to writing.
f1.Close
Response.Write "Moving file to c:\tmp <br>"
' Get a handle to the file in root of C:\.
Set f2 = fso.GetFile("c:\testfile.txt")
' Move the file to \tmp directory.
f2.Move ("c:\tmp\testfile.txt")
Response.Write "Copying file to c:\temp <br>"
' Copy the file to \temp.
f2.Copy ("c:\temp\testfile.txt")
Response.Write "Deleting files <br>"
' Get handles to files' current location.
Set f2 = fso.GetFile("c:\tmp\testfile.txt")
Set f3 = fso.GetFile("c:\temp\testfile.txt")
' Delete the files.
f2.Delete
f3.Delete
Response.Write "All done!"
End Sub
[JScript]
function ManipFiles()
{
var fso, f1, f2, s;
fso = new ActiveXObject("Scripting.FileSystemObject");
f1 = fso.CreateTextFile("c:\\testfile.txt", true);
Response.Write("Writing file <br>");
// Write a line.
f1.Write("This is a test.");
// Close the file to writing.
f1.Close();
Response.Write("Moving file to c:\\tmp <br>");
// Get a handle to the file in root of C:\.
f2 = fso.GetFile("c:\\testfile.txt");
// Move the file to \tmp directory.
f2.Move ("c:\\tmp\\testfile.txt");
Response.Write("Copying file to c:\\temp <br>");
// Copy the file to \temp.
f2.Copy ("c:\\temp\\testfile.txt");
Response.Write("Deleting files <br>");
// Get handles to files' current location.
f2 = fso.GetFile("c:\\tmp\\testfile.txt");
f3 = fso.GetFile("c:\\temp\\testfile.txt");
// Delete the files.
f2.Delete();
f3.Delete();
Response.Write("All done!");
}


mvh

sMorch

Kommentar
Fra : crha


Dato : 06-03-03 08:47

WoW... thx der... Det skal lige testes når jeg engang kommer hjem :)

Kommentar
Fra : smorch


Dato : 06-03-03 08:55

Her er et godt sted at læse om filesystemsobject og en del forskellige scripts:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/sgfilesystemobjectmodel.asp

Mvh
sMorch

Kommentar
Fra : crha


Dato : 07-03-03 21:08

Der er jo VBScript :(

Skal bruge det til ASP...

Kommentar
Fra : smorch


Dato : 07-03-03 22:57

Det du skriver mellem <% og %> i en asp fil er vbscript

sMorch

Kommentar
Fra : crha


Dato : 07-03-03 23:08

hmm... man kan lave noget der hedder

<script language="vbscript">

og netscape understøtter det vist ikke, men understøtter ASP, så helt det samme er det vel ikke?

Kommentar
Fra : smorch


Dato : 07-03-03 23:33

Det er din server der skal kunne køre asp - det har intet med browseren at gøre.
Je gakn skrive noget mere i morgen

sMorch

Kommentar
Fra : crha


Dato : 07-03-03 23:39

k :)

Kommentar
Fra : smorch


Dato : 08-03-03 10:58

Jeg vil foreslå du starter med at læse asp tutorial på www.html.dk . I det er der i lektion 14 - 15 - 16 beskrevet "the basics" i at bruge filesystem. Derefter vil det jeg ellers har lagt ind hér være lettere at gå til.

Mvh


sMorch

Kommentar
Fra : smorch


Dato : 10-03-03 15:53

Halloooooooo

Er du der endnu, eller gik du død.....

Kommentar
Fra : crha


Dato : 10-03-03 17:46

Yup jeg er her, sorry jeg ikke lige skrev.

Kan ikke få det til at virke. Hvis jeg bruger koden i vbs filer, så virker det, men ikke hvis jeg bruger det i ASP

Kommentar
Fra : smorch


Dato : 10-03-03 18:52

Prøv lige at sende mig et eksempel på din asp fil


http://morch.dk/indexlm.html tryk på contact

sMorch

Kommentar
Fra : Harlekin


Dato : 21-03-03 12:01

Du skriver det ikke virker... har du husket at skrive <%@ Language=VBScript %> i toppen af din ASP fil?

Kommentar
Fra : crha


Dato : 21-03-03 16:12

Ja, jeg har prøvet med følgende i en fil:

<%@ Language=VBScript %>


<%
Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("testfile.txt", True)
MyFile.WriteLine("This is a test. en fed test, lad os se hvad den kan :)")
MyFile.Close
%>

Men det virker ikke

Kommentar
Fra : smorch


Dato : 21-03-03 16:20

Hvilken fejlmeddelelse får du (kopier den og sæt den hind her på siden) ?

Kommentar
Fra : crha


Dato : 21-03-03 21:47

The page cannot be displayed
There is a problem with the page you are trying to reach and it cannot be displayed.

--------------------------------------------------------------------------------

Please try the following:

Open the cruckie.net home page, and then look for links to the information you want.
Click the Refresh button, or try again later.

Click Search to look for information on the Internet.
You can also see a list of related sites.




HTTP 500 - Internal server error
Internet Explorer


Kommentar
Fra : smorch


Dato : 21-03-03 22:45

For at vi kan se den egentlige fejlmeddelelse, skal du i din browser i Internetindstillinger > Fanebladet Avanceret, slå "Vis meddelelser om uskadelige fejlmeddelelser" fra og så køre scriptet igen, kopier fejlen og vis den hér.

Eller sætte et link på til scriptet.

Mvh

sMorch

Kommentar
Fra : Harlekin


Dato : 22-03-03 09:42

ja, ellers skriver du i toppen af koden:
<% on error resume next %>
og i bunden af koden
<% response.write err.number & " - " & err.description %>

så fanger du fejlen - også hvis koden ligger uploadet hos en webhost hvor du ikke kan komme til at sætte ovenstående indstillinger på serveren.

Kommentar
Fra : smorch


Dato : 22-03-03 21:06

Det er ikke på serveren der skal indstilles, men i Internet Explorer !!!!!!!!!!!!

sMorch

Kommentar
Fra : crha


Dato : 23-03-03 11:03
Kommentar
Fra : Harlekin


Dato : 23-03-03 12:39

smooch: ...mit forslag vil også løse problemet

Kommentar
Fra : smorch


Dato : 23-03-03 12:56

Der er ikke skrivetilladelse i den mappe du forsøger at oprette filen i. Det giver følgende fejl:

Microsoft VBScript runtime error '800a0046'

Permission denied

/man/createfile.asp, line 7


Mvh
sMorch

Kommentar
Fra : crha


Dato : 23-03-03 13:10

hmmmmm, jeg kan sagtens skrive til databaser osv.

Kommentar
Fra : smorch


Dato : 23-03-03 14:36

Ligger createfile.asp i samme mappe som en af de databaser du godt kan skrive til ? Hvis ikke så prøv at lægge den der .

sMorch

Kommentar
Fra : crha


Dato : 23-03-03 17:54

Yup, har prøvet det, men det virker ikke :(

Accepteret svar
Fra : smorch

Modtaget 100 point
Dato : 23-03-03 19:34

Send mig filen, så jeg selv kan teste den et sted hvor jeg ved der er skrivetilladelse

http://morch.dk/indexlmhtml tryk på contact

sMorch

Kommentar
Fra : crha


Dato : 24-03-03 16:26

wee, det virker nu :)

Opret en fil f.eks.


<%
Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile(server.MapPath("/mappe") & "/testfile.txt", True)
MyFile.WriteLine("This is a test.")
MyFile.Close
%>


Du har følgende muligheder
Eftersom du ikke er logget ind i systemet, kan du ikke skrive et indlæg til dette spørgsmål.

Hvis du ikke allerede er registreret, kan du gratis blive medlem, ved at trykke på "Bliv medlem" ude i menuen.
Søg
Reklame
Statistik
Spørgsmål : 177414
Tips : 31962
Nyheder : 719565
Indlæg : 6407845
Brugere : 218876

Månedens bedste
Årets bedste
Sidste års bedste