Solved

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

Posted on 2006-06-17
6
616 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now