Solved

Extra character with : Shell "cmd.exe /C copy ...."

Posted on 2006-06-17
6
627 Views
Last Modified: 2012-06-21
Hi There,

I have an ACCESS routine that creates creates a csv file of records that then inserts a header record to the top of the file.

To do this, I create the main csv file ("Main.csv") and then the header file ("Header.csv"), and then use the DOS COPY command to append the 'main' file to the 'header' file.  The command line is:

Shell "cmd.exe /C copy " & strpath & "Header.csv + " & strpath & "Main.csv " & strpath & "OutputFile.csv".

This appears to work fine, however the resulting file ("Output.csv") has the following character (by itself) on the last line : ""

The "" is not the intermediate file "Main.csv" when I look at it before deleting it.

Any ideas?

Cheers,
Mike

0
Comment
Question by:mmorr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 16928552
another way in DOS is to use TYPE, have u tried that?

type file1 >> file2

puts file1 on the end of file2

other way would be to write your own routine in vba
open both files and write to new file - easily done
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16928582
this bit of code
copies file test.xt and two.txt into a new file called new.txt

Public Sub CopyTwoFiles()

    Dim iFile1 As Integer
    Dim iFile2 As Integer
    Dim iFile3 As Integer
    Dim sLine As String
   
   
    iFile1 = FreeFile
    Open "c:\ee\test.txt" For Input As iFile1
   
    iFile2 = FreeFile
    Open "c:\ee\two.txt" For Input As iFile2
   
    iFile3 = FreeFile
    Open "c:\ee\new.txt" For Output As iFile3
   
   
    'Read File 1 and write to new file
    Do While Not EOF(iFile1)
       Line Input #iFile1, sLine
       Print #iFile3, sLine
    Loop
   
    'Read File 2 and write to new file
    Do While Not EOF(iFile2)
       Line Input #iFile2, sLine
       Print #iFile3, sLine
    Loop
   
    Close (iFile1)
    Close (iFile2)
    Close (iFile3)
End Sub
0
 

Author Comment

by:mmorr
ID: 16928587
Thanks rockiroads.

I tried the following in my vba routine, but it didn't append "Main.csv" to the end of "Header.csv".

Shell "cmd.exe TYPE " & strpath & "Main.csv >> " & strpath & "Header.csv "

Have I go the syntax correct?

Cheers,
M
0
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 65

Accepted Solution

by:
rockiroads earned 250 total points
ID: 16928599
dont u need the /C?

e.g.

cmd.exe /c TYPE
0
 
LVL 58

Expert Comment

by:harfang
ID: 16929620
Hello mmorr

I believe that the "" is a lone CR or LF character, while a normal line break would be a CR/LF pair. Have you tried using your file as it is? It might not be a problem at all.

Another idea would be to use the /a switch for COPY to make sure you get an ASCII copy, not a binary copy:

    Shell Environ("comspec") & " /c COPY /a ...."

If that fails, I would go with rockiroads suggestion to use Line Input and Print to recreate all CR/LF pairs afresh.

(°v°)
0
 

Author Comment

by:mmorr
ID: 16930763
Thanks rockiroads.  Adding the "/C" back in fixed the problem - put main.csv on the end of header.csv with no "".
Thanks also harfang for your comment - I tried but still got the "".
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question