Sign in to follow this  
Followers 0
schilbiz

Append Files - String issue.

3 posts in this topic

Hey guys, I am working on a simple script to append multiple files to one. Most of it is complete, I am having trouble adding a "+" to the string that is being run.

You can append multiple files with a simple command, examples:

copy source destination

copy source+source+source destination

copy c:\file1.txt+c:\file2.txt+c:\windows\test.txt C:\test\appended.txt

If you run the script, you will notice that there is no "+" between the files, I have been able to get a "+" before all files I want to append, with StringReplace, but not just in between them.

Uncomment ;Run($runstring) to get it to run the string.. but if you can help I am sure you can figure that out. Thanks!

#include <GuiConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)

$MainGUI = GUICreate("Append Files",250,265, @DesktopHeight*.25, @DesktopHeight*.25,$WS_SIZEBOX+$WS_SYSMENU)

$L_mainGUI1 = GuiCtrlCreateLabel("1. Set the path\file destination to what file you want to append the files to.",10,90,230,30)
$L_mainGUI2 = GuiCtrlCreateLabel("2. Select Append to choose the file(s) to append. If the destination file does not exist it will be created.",10,125,230,45)
$L_Appendto = GuiCtrlCreateLabel("Path\File to Append files to:",10,30,150,23)
$Appendto = GuiCtrlCreateInput("C:\test\temp.txt", 10, 55, 215, 20)
$Append = GuiCtrlCreateButton("Append", 30, 185, 70, 23)
$Close = GuiCtrlCreateButton("Close", 150, 185, 70, 23)


GUICtrlSetOnEvent($Close, "Close")
GUICtrlSetOnEvent($Append, "Append")
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
GuiSetState()

While 1
    Sleep(1000)
WEnd

Func Append()
    $message = "Select the files you want to Append."
    $Files = FileOpenDialog($message, "C:" & "\", "Text Files (*.txt)", 1 + 4 )
If @error Then
    MsgBox(16, "Try Again", "No Files Selected", 2)
Else
    $Files = StringReplace($Files, "|", @CRLF)
    $Copied = GUICtrlRead ($Appendto)
    $runstring = @ComSpec & " /c " & StringFormat('copy %s %s',$Files,$Copied, @SW_HIDE)
        MsgBox(4096,"Runstring",$runstring)
        ;Run($runstring)
EndIf
EndFunc

Func Close()
  Exit
EndFunc

Share this post


Link to post
Share on other sites



Hey guys, I am working on a simple script to append multiple files to one. Most of it is complete, I am having trouble adding a "+" to the string that is being run.

You can append multiple files with a simple command, examples:

copy source destination

copy source+source+source destination

copy c:\file1.txt+c:\file2.txt+c:\windows\test.txt C:\test\appended.txt

If you run the script, you will notice that there is no "+" between the files, I have been able to get a "+" before all files I want to append, with StringReplace, but not just in between them.

Uncomment ;Run($runstring) to get it to run the string.. but if you can help I am sure you can figure that out. Thanks!

#include <GuiConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)

$MainGUI = GUICreate("Append Files",250,265, @DesktopHeight*.25, @DesktopHeight*.25,$WS_SIZEBOX+$WS_SYSMENU)

$L_mainGUI1 = GuiCtrlCreateLabel("1. Set the path\file destination to what file you want to append the files to.",10,90,230,30)
$L_mainGUI2 = GuiCtrlCreateLabel("2. Select Append to choose the file(s) to append. If the destination file does not exist it will be created.",10,125,230,45)
$L_Appendto = GuiCtrlCreateLabel("Path\File to Append files to:",10,30,150,23)
$Appendto = GuiCtrlCreateInput("C:\test\temp.txt", 10, 55, 215, 20)
$Append = GuiCtrlCreateButton("Append", 30, 185, 70, 23)
$Close = GuiCtrlCreateButton("Close", 150, 185, 70, 23)


GUICtrlSetOnEvent($Close, "Close")
GUICtrlSetOnEvent($Append, "Append")
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
GuiSetState()

While 1
    Sleep(1000)
WEnd

Func Append()
    $message = "Select the files you want to Append."
    $Files = FileOpenDialog($message, "C:" & "\", "Text Files (*.txt)", 1 + 4 )
If @error Then
    MsgBox(16, "Try Again", "No Files Selected", 2)
Else
    $Files = StringReplace($Files, "|", @CRLF)
    $Copied = GUICtrlRead ($Appendto)
    $runstring = @ComSpec & " /c " & StringFormat('copy %s %s',$Files,$Copied, @SW_HIDE)
        MsgBox(4096,"Runstring",$runstring)
        ;Run($runstring)
EndIf
EndFunc

Func Close()
  Exit
EndFunc
Maybe this will work

Func Append()
    $message = "Select the files you want to Append."
    $Files = FileOpenDialog($message, "C:" & "\", "Text Files (*.txt)", 1 + 4 )
If @error Then
    MsgBox(16, "Try Again", "No Files Selected", 2)
Else
    $Files = StringReplace($Files, "|", '" + "')
    $Copied = GUICtrlRead ($Appendto)
    $runstring = @ComSpec & " /c " & StringFormat('copy "%s %s"',$Files,$Copied, @SW_HIDE)
        MsgBox(4096,"Runstring",$runstring)
       ;Run($runstring)
EndIf
EndFunc

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Hey guys, I am working on a simple script to append multiple files to one. Most of it is complete, I am having trouble adding a "+" to the string that is being run.

You can append multiple files with a simple command, examples:

copy source destination

copy source+source+source destination

copy c:\file1.txt+c:\file2.txt+c:\windows\test.txt C:\test\appended.txt

If you run the script, you will notice that there is no "+" between the files, I have been able to get a "+" before all files I want to append, with StringReplace, but not just in between them.

Uncomment ;Run($runstring) to get it to run the string.. but if you can help I am sure you can figure that out. Thanks!

#include <GuiConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)

$MainGUI = GUICreate("Append Files",250,265, @DesktopHeight*.25, @DesktopHeight*.25,$WS_SIZEBOX+$WS_SYSMENU)

$L_mainGUI1 = GuiCtrlCreateLabel("1. Set the path\file destination to what file you want to append the files to.",10,90,230,30)
$L_mainGUI2 = GuiCtrlCreateLabel("2. Select Append to choose the file(s) to append. If the destination file does not exist it will be created.",10,125,230,45)
$L_Appendto = GuiCtrlCreateLabel("Path\File to Append files to:",10,30,150,23)
$Appendto = GuiCtrlCreateInput("C:\test\temp.txt", 10, 55, 215, 20)
$Append = GuiCtrlCreateButton("Append", 30, 185, 70, 23)
$Close = GuiCtrlCreateButton("Close", 150, 185, 70, 23)


GUICtrlSetOnEvent($Close, "Close")
GUICtrlSetOnEvent($Append, "Append")
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
GuiSetState()

While 1
    Sleep(1000)
WEnd

Func Append()
    $message = "Select the files you want to Append."
    $Files = FileOpenDialog($message, "C:" & "\", "Text Files (*.txt)", 1 + 4 )
If @error Then
    MsgBox(16, "Try Again", "No Files Selected", 2)
Else
    $Files = StringReplace($Files, "|", @CRLF)
    $Copied = GUICtrlRead ($Appendto)
    $runstring = @ComSpec & " /c " & StringFormat('copy %s %s',$Files,$Copied, @SW_HIDE)
        MsgBox(4096,"Runstring",$runstring)
        ;Run($runstring)
EndIf
EndFunc

Func Close()
  Exit
EndFunc
The DOS copy command was useful back in the day, but in the era of long file and folder names it has been rendered rather clunky. Here is a more efficient way to what you were trying to do.

#include <GuiConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
Opt("GUIOnEventMode", 1)

Dim $avFile

$MainGUI = GUICreate("Append Files",250,265, @DesktopHeight*.25, @DesktopHeight*.25,$WS_SIZEBOX+$WS_SYSMENU)

$L_mainGUI1 = GuiCtrlCreateLabel("1. Set the path\file destination to what file you want to append the files to.",10,90,230,30)
$L_mainGUI2 = GuiCtrlCreateLabel("2. Select Append to choose the file(s) to append. If the destination file does not exist it will be created.",10,125,230,45)
$L_Appendto = GuiCtrlCreateLabel("Path\File to Append files to:",10,30,150,23)
$Appendto = GuiCtrlCreateInput("C:\test\temp.txt", 10, 55, 215, 20)
$Append = GuiCtrlCreateButton("Append", 30, 185, 70, 23)
$Close = GuiCtrlCreateButton("Close", 150, 185, 70, 23)


GUICtrlSetOnEvent($Close, "Close")
GUICtrlSetOnEvent($Append, "Append")
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
GuiSetState()

While 1
    Sleep(1000)
WEnd

Func Append()
    $message = "Select the files you want to Append."
    $Files = FileOpenDialog($message, "C:" & "\", "Text Files (*.txt)", 1 + 4 )
    If @error Then
        MsgBox(16, "Try Again", "No Files Selected", 2)
    Else
        $Copied = GUICtrlRead ($Appendto)
        $result = StringInStr($Files,"|")
        $Folder = StringLeft($Files,($result - 1))
        $Files = StringRight($Files,(StringLen($Files) - $result))
        $newfile = FileOpen($Copied, 9)
        $Source = StringSplit($Files,"|")
        
        For $sFile = 1 to $Source[0]
            _FileReadToArray($Folder & $Source[$sFile], $avFile)
            If IsArray($avFile) Then
                If $avFile[0] > 0 Then
                    For $n = 1 To $avFile[0]
                        FileWrite($newfile,$avFile[$n] & @CRLF)
                    Next
                    FileWrite($newfile,@CRLF)
                EndIf
            EndIf
            $avFile = ""
        Next
        FileClose($newfile)
        MsgBox(0,"","Files Appended")
    EndIf
EndFunc

Func Close()
  Exit
EndFunc

Share this post


Link to post
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
Sign in to follow this  
Followers 0