1

i am trying to copy a file from a local drive to a Network storage. The file is a TXT file with 6380 lines. Opening the Target file, the copy of the file is not complete, it stops at line 6285 in the middle of the line. The File Itself is a G-Code with 103 kb.

Source File Line 6285: "Z17.168 Y7.393" and the file continues...

Target File Line 6285: "Z17.168 Y7.3" after this its the end of the file.

I tired several differnt copy operations:

from shutil import copyfile
copyfile(WorkDir + FileName, CNCDir + FileName)

or

os.system("copy "+WorkDir + FileName +" " + CNCDir + FileName)

or also the DOS XCOPY command. The weird thing is, that if i perform the copy command in a separate dos window with the same syntax it works perfect, just by executing it from the PYTHON script, it does not copy the complete file.

Any ideas?

Stephen Docy
  • 4,738
  • 7
  • 18
  • 31
m0h
  • 11
  • 2
  • Is the file USBCNC4.0.x type? – ZF007 Feb 18 '18 at 10:17
  • The G-code itself is created with "F-Engrave", its also pyhton based. i am extracting the G-Code in batch mode and create my own file. So this is not a special format or synthax. Its just a TXT file and i rename ot to .SPF for a CNC Subroutine. – m0h Feb 18 '18 at 12:30
  • F-Engrave seems okay. Try option 3 to see if its just a memory loading issue. – ZF007 Feb 18 '18 at 13:12

2 Answers2

0

Get a few "debugging" conformation using the following:

Option 1 (blunt reading, should print content to cmd console or editor stdout):

file = open(“testfile.text”, “r”) 
print file.read() 

Option 2 (reading + loading filecontent into memory, write content from memory to new file):

file          = open(“testfile.text”, “r”)
count_lines   = 0
counted_lines = 6380 
content       = []

for line in file:

    count_line += 1
    content.append(line)
    print 'row :  "%s" content : "%s"' % (count_lines, file)

if counted_lines == count_lines:
    dest_file = open(“new_testfile.txt”,”w”)
    for item in content:
        dest_file.write(item)
    dest_file.close()
else:
    print 'error at line : %s' % count_lines

Option 3 (excludet character issue at line 6285 and show its a memory loading issue):

from itertools import islice

# Print the "6285th" line.
with open(“testfile.text”) as lines:
    for line in islice(lines, 6284, 6285):
        print line

Option 4 is found here.

and

Option 5 is:

import linecache

linecache.getline(“testfile.text”, 2685)
ZF007
  • 3,708
  • 8
  • 29
  • 48
  • With slight modification you can make from option three a batch-wise process and cut the read/write into two parts: 1) lines (1,600) and 2) lines (6001, 6380) and paste them where " 6284", "6285" is written down. – ZF007 Feb 18 '18 at 13:27
  • Ye the workaround for me is that i am keeping the G-Code in a file and just writing a second output file to the drive. Thats how I solved it for now. Still then i am interested why a copy of the file does not work. – m0h Feb 18 '18 at 13:51
  • Strange... that none of the options worked out... I'm almost starting to believe you got a bad-sector on your HDD or SDD at that specific location. Try to leave the file as is and generate a new file with different name. If this works conduct some disk-drive diagnostics... reading/writing 100mb files is like driving with "two fingers in your nose" for python ;-) – ZF007 Feb 18 '18 at 13:59
  • Ok now i changed from the network drive to a local drive. Still the same issue. Line 6285 but this time it stops at the "Z". I dont think its an issue of the HDD. I am starting the .py scrit with a .bat file in windows. there would be also the opiton to add the copy command here but still then its a workaround and it does not work. – m0h Feb 18 '18 at 14:13
  • Lol... then we stick to a unknown cache problem somewhere... maybe checking software versions of python and other libraries to latest? Perhaps you can get rid of it that way. Or just cold-boot your pc..might help as last resort. Anyhow, your workaround works... GL.. I'm logging of for a bit to do real-world stuff like a walk in the park. Maybe someone else has some "debugging" solutions for finding this "bug". – ZF007 Feb 18 '18 at 14:20
0

Using Option 1 on the target file gives me:

Z17.154 Y7.462
Z17.159 Y7.439
Z17.163 Y7.416
Z17.168 Y7.3
"done"
Press any key to continue . . .

Using Option 2 gives:

row :  "6284" content : "<open file 'Z:\\10-Trash\\APR_Custom.SPF', mode 'r' at 0x0000000004800AE0>"
row :  "6285" content : "<open file 'Z:\\10-Trash\\APR_Custom.SPF', mode 'r' at 0x0000000004800AE0>"

And a TXT File with the same content like the Target file:

Last 3 lines:

Z17.159 Y7.439
Z17.163 Y7.416
Z17.168 Y7.3

I tried option 4 -6 aswell but i dont see a purpose behind that. With Option 5 I had to change the line numbe to 6284 because list was out of range with that number.

from itertools import islice

# Print the "6285th" line.
with open(CNCDir + FileName) as lines:
    for line in islice(lines, 6284, 6285):
        print "Option 3:"
        print line

f=open(CNCDir + FileName)
lines=f.readlines()
print "Option 4:"
print lines[6284]

import linecache
print "Option 5:"
print linecache.getline(CNCDir + FileName, 6285)

Out file from Command line:

    Copy to CNC:

Source: C:\F-Engrave\WorkDir\APR_Custom.SPF
Traget: Z:\10-Trash\APR_Custom.SPF

Option 3:
Z17.168 Y7.3
Option 4:
Z17.168 Y7.3
Option 5:
Z17.168 Y7.3

"done"
Press any key to contiune. . .
m0h
  • 11
  • 2