Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2006-06-17
6
Medium Priority
?
667 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
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 65

Accepted Solution

by:
rockiroads earned 1000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
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…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

885 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