AutoHotkey Community

It is currently May 27th, 2012, 12:20 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: September 1st, 2005, 9:22 pm 
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?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2005, 11:00 pm 
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. :roll:


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2005, 11:08 pm 
Offline

Joined: August 14th, 2005, 1:38 am
Posts: 82
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 2nd, 2005, 12:55 am 
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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 2nd, 2005, 6:30 am 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
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
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 2nd, 2005, 6:56 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 2nd, 2005, 7:11 pm 
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?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 2nd, 2005, 7:29 pm 
Offline

Joined: November 6th, 2004, 11:03 am
Posts: 170
Location: Salt Lake City, UT
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 ;)

EDIT: it actually looks a lot like BoBo's script :oops:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 2nd, 2005, 7:55 pm 
ranomore wrote:
Quote:
it actually looks a lot like BoBo's script
Hm, hope you've paid the license already ?! :lol::wink:


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 2nd, 2005, 9:16 pm 
wow, thanks, worked perfectly how i wanted it to. thanks for your help guys. i am truley grateful. Will save us hours of "clicking." :D


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 7th, 2005, 12:07 am 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 7th, 2005, 1:31 am 
Offline

Joined: July 25th, 2005, 10:20 pm
Posts: 139
Location: Richmond, Virginia
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 7th, 2005, 2:19 am 
thanks everyone, that worked perfectly


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Leef_me, Pulover, rjgatito, XstatyK, Yahoo [Bot] and 23 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group