Copy info from txt and paste in another vbscript

13,041

Solution 1

This works for me:

'//OPEN FILE and READ
Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile("C:\vnc.txt",1)
strFileText = objFileToRead.ReadAll()
objFileToRead.Close


' ///PASTE 
Set objFSO = CreateObject("Scripting.FileSystemObject") 
Set objFileToWrite = objFSO.OpenTextFile("c:\vnc.vnc", 2)
objFileToWrite.Write strFileText
objFileToWrite.Close

The only difference I made was remove the subfolder, and put in the root of C: The script worked.

I manually created both the source file and target file. If both files exist, and are not locked (as if you had it open / locked in another application), then the permissions of that VNC folder must be the issue.

Solution 2

If still your file permission denied you to write then you have to do change the security of that file using right click of mouse, and update advanced setting.

Share:
13,041
Mr_Geeeee
Author by

Mr_Geeeee

Updated on June 04, 2022

Comments

  • Mr_Geeeee
    Mr_Geeeee almost 2 years

    I'm trying to copy a line of text from a .txt -> paste into another file and save. The code I have keeps giving me errors at the paste section. I am completely new at this and learning as I go. My main goal is to paste the info after Host= in another file. But I need to get this down first.

    Here is my code so far

     ///OPEN FILE and READ
    Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile("C:\vnc\vnc.txt",1)
    strFileText = objFileToRead.ReadAll()
    objFileToRead.Close
    
    
    ' ///PASTE 
    Set objFSO = CreateObject("Scripting.FileSystemObject") 
    Set objFileToWrite = objFSO.OpenTextFile("c:\vnc\testfile.vnc", 2)
    objFileToWrite.Write strFileText
    objFileToWrite.Close
    
  • Mr_Geeeee
    Mr_Geeeee about 11 years
    I found out what was creating the folder would override the folders permission putting it into Read-Only. Thanks