AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

help: I need to join numerous txt files into a single txt bu

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
stashy
Guest





PostPosted: Thu Sep 01, 2005 9:22 pm    Post subject: help: I need to join numerous txt files into a single txt bu Reply with quote

hi i really need help. I need to join several txt files into a single txt file daily. the only problem is that every txt file has the same name, each placed in its own folder. the name for every folder that contains the txt files are not consistent. (every day I get an email attachment that arrives in a folder with a unique name. So i have say 35 folders, each containing a "".txt file. every folder has a different name, never the same each day. How do i do this? Any help will be greatly appreciated.

i case the above is not understandable. my directories look like this:

c:\temp
c:\temp\0005folder\file.txt
c:\temp\54851folder\file.txt
c:\temp\887616folder\file.txt

how would i join these txt files, if i dont know what the folder (directory) will be?
Back to top
BoBo
Guest





PostPosted: Thu Sep 01, 2005 11:00 pm    Post subject: Reply with quote

Quote:
Copies one or more files to another location.

COPY [/D] [/V] [/N] [/Y | /-Y] [/Z] [/A | /B ] source [/A | /B]
[+ source [/A | /B] [+ ...]] [destination [/A | /B]]

To append files, specify a single file for destination, but multiple files
for source (using wildcards or file1+file2+file3 format).


Code:
Loop, C:\TEMP\file.txt, 0, 1
{
   If A_Index = 1
       FileList = %A_LoopFileFullPath%
   FileList := FileList "+" A_LoopFileFullPath
}
Run, cmd /c copy %FileList% MergedFile.txt,, Hide
Not tested. Rolling Eyes
Back to top
wildfire



Joined: 14 Aug 2005
Posts: 75

PostPosted: Thu Sep 01, 2005 11:08 pm    Post subject: Reply with quote

Possibly you could use FileSelectFile to manually select the files, then use FileRead and FileAppend.

Example:
Code:
FileSelectFile, firstFile,, C:\temp\, Choose the First File, Documents (*.txt)
FileSelectFile, secondFile,, C:\temp\, Choose the Second File, Documents (*.txt)
FileSelectFile, thirdFile,, C:\temp\, Choose the Third File, Documents (*.txt)
FileSelectFile, fourthFile,, C:\temp\, Choose the Fourth File, Documents (*.txt)

FileRead, firstFileContents, %firstFile%
FileRead, secondFileContents, %secondFile%
FileRead, thirdFileContents, %thirdFile%
FileRead, fourthFileContents, %fourthFile%

FileAppend, %firstFileContents%, newfile.txt
FileAppend, %secondFileContents%, newfile.txt
FileAppend, %thirdFileContents%, newfile.txt
FileAppend, %fourthFileContents%, newfile.txt
Back to top
View user's profile Send private message
stashy
Guest





PostPosted: Fri Sep 02, 2005 12:55 am    Post subject: Reply with quote

thanks guys, you guys really are geniouses. Wildfire, your script seems to work pretty good, though Im wondering if there is any way that i can use this without any manual input from the user (fileselectfile) though that worked well for me.. Im trying to bypass manual input so others can do the tasks easily.

Also, i cant seem to get the carriage return to work in this script. where do you place `r, if i wanted to have at least 5 empty lines before the second file is appended to the new file?

thanks a lot for your help. im greatly appreciative.
Back to top
toralf



Joined: 31 Jan 2005
Posts: 3842
Location: Bremen, Germany

PostPosted: Fri Sep 02, 2005 6:30 am    Post subject: Reply with quote

Hi Stashy,

You can place `n`n`n`n`n before the content of the second file. That will insert 5 empty line.

If you do not want to input the names manually, how should the script know which files it should combine? How do you want the script to give the information?
A very confienent and easy way would be a GUI with drag&drop support.
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
stashy
Guest





PostPosted: Fri Sep 02, 2005 6:56 pm    Post subject: Reply with quote

sorry, but i just began researching scripts and macros to try to find a solution for this one time consumning task we have at work. thanks Toralf, im looking into GUI's at the moment. but i keep getting this wierd font- a box symbol in my newfile.txt for every `n i put. maybe this is basic stuff, but what am i doing wrong?
this is what im doing after the fileread....


FileAppend, %firstFileContents%, c:\newfile.txt
FileAppend, `n`n`n`n`n%secondFileContents%, c:\newfile.txt
FileAppend, `n`n`n`n`n%thirdFileContents%, c:\newfile.txt
FileAppend, `n`n`n`n`n%fourthFileContents%, c:\newfile.txt
Back to top
stashy
Guest





PostPosted: Fri Sep 02, 2005 7:11 pm    Post subject: Reply with quote

nevermind sorry, i experimented and got it. i started putting `r`n`r`n`r`n and then it seemed to work ok, dont know why, but thanks anyway.

i was wondering though, if anyone knows if i can write a script telling it to look in a folder and count the number of folders within it...then do a fileselectfile in which it will ask for THAT specific number of files ( the #of folders it counted) then proceed with fileread and fileappend? is this possible?
Back to top
ranomore



Joined: 06 Nov 2004
Posts: 178
Location: Salt Lake City, UT

PostPosted: Fri Sep 02, 2005 7:29 pm    Post subject: Reply with quote

http://www.autohotkey.com/docs/commands/LoopFile.htm

I think the Recurse option is what you are looking for.

Code:
inFileLocation = C:\Temp\*.txt
Loop,%inFileLocation%,0,1
{
   FileRead,fileContents,%A_LoopFileFullPath%
   if a_index = 1
      FileAppend,File %a_index%: %A_LoopFileFullPath%`n`n%fileContents%,newfile.txt
   Else
      FileAppend,`n`nFile %a_index%: %A_LoopFileFullPath%`n`n`n%fileContents%,c:\newfile.txt
}


untested Wink

EDIT: it actually looks a lot like BoBo's script Embarassed
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
BoBo
Guest





PostPosted: Fri Sep 02, 2005 7:55 pm    Post subject: Reply with quote

ranomore wrote:
Quote:
it actually looks a lot like BoBo's script
Hm, hope you've paid the license already ?! LaughingWink
Back to top
stashy
Guest





PostPosted: Fri Sep 02, 2005 9:16 pm    Post subject: Reply with quote

wow, thanks, worked perfectly how i wanted it to. thanks for your help guys. i am truley grateful. Will save us hours of "clicking." Very Happy
Back to top
stashy
Guest





PostPosted: Wed Sep 07, 2005 12:07 am    Post subject: Reply with quote

hi, thanks for all your previous help, but now i was wondering if there is a way to display a Msgbox that will tell me the
number of files I have appended...a count of the n
Back to top
Litmus Red



Joined: 25 Jul 2005
Posts: 139
Location: Richmond, Virginia

PostPosted: Wed Sep 07, 2005 1:31 am    Post subject: Reply with quote

Based on BoBo/Ranomore's script:

Code:
inFileLocation = C:\Temp\*.txt
Loop,%inFileLocation%,0,1
{
   FileRead,fileContents,%A_LoopFileFullPath%
   if a_index = 1
      FileAppend,File %a_index%: %A_LoopFileFullPath%`n`n%fileContents%,c:\newfile.txt
   Else
      FileAppend,`n`nFile %a_index%: %A_LoopFileFullPath%`n`n%fileContents%,c:\newfile.txt
   FileNo := A_Index
}
MsgBox, , , %FileNo% files were combined., 2
Return
Back to top
View user's profile Send private message
stashy
Guest





PostPosted: Wed Sep 07, 2005 2:19 am    Post subject: Reply with quote

thanks everyone, that worked perfectly
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group