Jump to content

copy text from .txt file without opening


Recommended Posts

Wasn't an answer, wasn't meant to "answer" you, was meant to show you what you are doing wrong, which in your case is basically everything, search the forums, read the help file, try coming up with something better then you will get ways of doing things the right way, you won't get answers for questions that are never asked in the 1st place.

Link to comment
Share on other sites

The helpfile also says

FileWrite

If a filename is given rather than a file handle, the file will be opened and closed during the function call. (...)  filename will be created if it does not already exist.

Therefore this code works

$file = @DesktopDir & "\t.txt"
FileWrite($file, "this is a test")

even if this can't be considered as good practice  :)

Link to comment
Share on other sites

To the OP, your script doesn't show that the file is being copied, you're just writing two characters (unprintable characters at that) to the end of the file.

What EXACTLY are you attempting to do?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Wasn't an answer, wasn't meant to "answer" you, was meant to show you what you are doing wrong, which in your case is basically everything, search the forums, read the help file, try coming up with something better then you will get ways of doing things the right way, you won't get answers for questions that are never asked in the 1st place.

You're doing the wrong way of showing that someone is wrong.. you didn't even show "HOW" the seeker is wrong.. you're just telling the meaning of the function..

I know that ,

FileWrite

Write text/data to the end of a previously opened file.

but didn't expect that you can't write "ctrl a" and "ctrl c"  at the end, since it is also has ASCII equivalent in the form of chr in autoIT.

Maybe its because its a control function..

you can just say that i can't do a control function at the end..

BUT You're just copying and pasting here the meaning of FileWrite functions

It is so annoying, did you know it?

Link to comment
Share on other sites

To the OP, your script doesn't show that the file is being copied, you're just writing two characters (unprintable characters at that) to the end of the file.

What EXACTLY are you attempting to do?

I thought that it will copy to the clipboard the text inside if a follow up the filewrite with control function of "ctrl a" and then "ctrl c". but it didn't work

i just wanted to copy the text inside .txt file without opening it

I also tried the run or execute function in HIDE mode but instead of copying the content of .txt file, it is just performing a "ctrl a" and "ctrl c" outside the file

Link to comment
Share on other sites

FileOpen, FileRead, FileClose. FileOpen creates a handle to the file, FileRead reads it into an array, FileClose closes the handle. After the text is in a variable, what you do with it is up to what you need to do with it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

FileOpen, FileRead, FileClose. FileOpen creates a handle to the file, FileRead reads it into an array, FileClose closes the handle. After the text is in a variable, what you do with it is up to what you need to do with it.

tnx i alredy done using fileread and filewrite.

$file = @DesktopDir & "\t.txt"
    $file2 = @DesktopDir & "\s.txt"

    $file1 = FileRead($file)
    FileWrite($file2,$file1)

it copies the text from t.txt to s.txt without opening the two text file

Link to comment
Share on other sites

You could also just use FileCopy instead of going about it in such a convoluted way.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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...