Author Topic: merge 2 txt files from 2 different directories  (Read 2450 times)

0 Members and 1 Guest are viewing this topic.

andrew_nao

  • Guest
merge 2 txt files from 2 different directories
« on: October 18, 2012, 02:25:20 PM »
does anyone have any code they can share that would merge 2 txt files from 2 different directories into 1 txt file in 1 directory?

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: merge 2 txt files from 2 different directories
« Reply #1 on: October 18, 2012, 02:48:22 PM »
Try this code .

Code - Auto/Visual Lisp: [Select]
  1. (defun c:Test (/ ff sf off osf str)
  2. ;;; Tharwat 18. Oct. 2012 ;;;
  3.   (if (and (setq ff (getfiled "Select source text file" "C:\\" "txt" 16))
  4.          (setq sf (getfiled "Select target tetxt file" "C:\\" "txt" 16))
  5.          )
  6.   (progn
  7.     (setq off (open ff "r"))
  8.     (setq osf (open sf "a"))
  9.     (write-line "\n" osf)
  10.     (while (setq str (read-line off))
  11.       (write-line str osf))
  12.     (close off)
  13.     (close osf)
  14.     )
  15.   )
  16. )
  17.  

pBe

  • Bull Frog
  • Posts: 402
Re: merge 2 txt files from 2 different directories
« Reply #2 on: October 19, 2012, 11:26:16 AM »
Code: [Select]
(vl-file-copy ff sf T)

ronjonp

  • Needs a day job
  • Posts: 7529
Re: merge 2 txt files from 2 different directories
« Reply #3 on: October 19, 2012, 11:42:33 AM »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Tharwat

  • Swamp Rat
  • Posts: 710
  • Hypersensitive
Re: merge 2 txt files from 2 different directories
« Reply #4 on: October 19, 2012, 12:01:06 PM »
Code: [Select]
(vl-file-copy ff sf T)

Nice function pBe.  :wink:

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

pBe

  • Bull Frog
  • Posts: 402
Re: merge 2 txt files from 2 different directories
« Reply #6 on: October 20, 2012, 06:20:40 AM »
Nice  8-)

Nice function pBe.  :wink:

Thank you guys  :-)

I would think its the most appropriate function to use in this case, But sometimes i use shell command mixed with lisp when dealing with multiple files for source.

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

  source       Specifies the file or files to be copied.
  /A           Indicates an ASCII text file.
  /B           Indicates a binary file.
  /D           Allow the destination file to be created decrypted
  destination  Specifies the directory and/or filename for the new file(s).
  /V           Verifies that new files are written correctly.
  /N           Uses short filename, if available, when copying a file with a
               non-8dot3 name.
  /Y           Suppresses prompting to confirm you want to overwrite an
               existing destination file.
  /-Y          Causes prompting to confirm you want to overwrite an
               existing destination file.
  /Z           Copies networked files in restartable mode.
  /L           If the source is a symbolic link, copy the link to the target
               instead of the actual file the source link points to.

The switch /Y may be preset in the COPYCMD environment variable.
This may be overridden with /-Y on the command line.  Default is
to prompt on overwrites unless COPY command is being executed from
within a batch script.

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