Jump to content

FileWrite did not work!


Recommended Posts

I have these codes:

$importData1=FileRead("temp.txt");
MsgBox(0,"",$importData1);
$file1=FileOpen("data1.txt", 2);
FileWrite($file1, $importData1);
FileClose($file1)

$importData2=FileRead("D:\Temp.txt");importData1 is different from importData2!
MsgBox(0,"",$importData2);
$file2=FileOpen("data2.txt", 2);
FileWrite($file2, $importData2);
FileClose($file2)

When I run the script, both of them show the data inside file temp.txt and D:\Temp.txt but only $importData1 is written to data1.txt and $importData2 is not.

The only difference between 2 codes is FileRead("temp.txt"); and FileRead("D:\Temp.txt") (Path) so

I think the problem about the same directory.

Fix for me plz!

Edited by nht3004

for(loop=0; loop<infinity; loop++) { alert('I love you'); }

Link to comment
Share on other sites

so your merging one file with another.?

look @ _filereadtoarray and _filewritefromarray in the helpfile.

Two files to write and read are totally different, how can I merge them bro, I still can't get it!

for(loop=0; loop<infinity; loop++) { alert('I love you'); }

Link to comment
Share on other sites

  • Moderators

nht3004,

The lines are not wrong, but they do not do what you want them to do! You have a logic problem, not a coding one. From your first post:

$file1=FileOpen("data1.txt", 2)

= Open a file called "data1.txt" and delete any existing file of that name.

$file2=FileOpen("data2.txt", 2)

= Open a file called "data2.txt" and delete any existing file of that name.

So you will get 2 files: "data1.txt" which is a copy of "temp.txt", and "data2.txt" which is a copy of "D:\Temp.txt".

If you want to merge them you need to open the same file twice - and use the "append" rather than the "delete" flag:

$importData1=FileRead(@ScriptDir & "\temp.txt");
MsgBox(0,"",$importData1);
$file1=FileOpen(@ScriptDir & "\data1.txt", 2)   ; Open file and delete existing file
FileWrite($file1, $importData1)   ; Write to file
FileClose($file1)
$importData2=FileRead"D:\Temp.txt")
MsgBox(0,"",$importData2);
$file1=FileOpen("\data1.txt", 1)    ; Open the same file for append to contents
FileWrite($file1, $importData2)   ; Append to existing file
FileClose($file1)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

welll.. it KINDA is a coding problem.. although those flags are in the help file ^_^

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...