Select to view content in your preferred language

Nested loop problem

4193
1
Jump to solution
01-16-2015 12:38 AM
JohannesBierer
Frequent Contributor

I do know it's not the python forum here around, but maybe someone knows that.

Need a migration script to copy folders. That's what I have so far:

import shutil, os, sys
# import numpy as np

QFile = r"R:\natura 2000\SG-Besprechungen\Migration2015_Q.txt"
ZFile = r"R:\natura 2000\SG-Besprechungen\Migration2015_Z.txt"

f = open(QFile, 'r')
for line in f:
    print(line)
    # print f.readline
    f1 = open(ZFile, 'r')
    for line1 in f1:
        print(line1)

    ##    src = line
    ##    dest = r"R:\SG-C\SIC_20150115"

        if sys.platform == 'win32':
            os.system('xcopy "%s" "%s"' % (line, line1) + " /Y /M /S /E /D")
            print 'xcopy "%s" "%s"' % (line, line1) + " /Y /M /S /E /D "
        else:
            shutil.copy(line, line1)

Result is that:

R:\natura 2000\8847.00 Richtlinien\Bauleitplanung

R:\SG-C\8850.20-1 Allgemeine Unterlagen Natura 2000

xcopy "R:\natura 2000\8847.00 Richtlinien\Bauleitplanung

" "R:\SG-C\8850.20-1 Allgemeine Unterlagen Natura 2000

" /Y /M /S /E /D

R:\SG-C\8850.20-2 Unterlagen aus anderen Bundesländern (Why that?)

xcopy "R:\natura 2000\8847.00 Richtlinien\Bauleitplanung

" "R:\SG-C\8850.20-2 Unterlagen aus anderen Bundesländern

" /Y /M /S /E /D

R:\natura 2000\8847.02 allgemein

R:\SG-C\8850.20-1 Allgemeine Unterlagen Natura 2000 (Double?)

xcopy "R:\natura 2000\8847.02 allgemein

" "R:\SG-C\8850.20-1 Allgemeine Unterlagen Natura 2000

" /Y /M /S /E /D

R:\SG-C\8850.20-2 Unterlagen aus anderen Bundesländern

xcopy "R:\natura 2000\8847.02 allgemein

" "R:\SG-C\8850.20-2 Unterlagen aus anderen Bundesländern

" /Y /M /S /E /D

0 Kudos
1 Solution

Accepted Solutions
JohannesBierer
Frequent Contributor

strip() was the solution ...

import shutil, os, sys

# import numpy as np

QFile = "R:\\natura 2000\\SG-Besprechungen\\Migration2015_Q_Test.txt"

ZFile = "R:\\natura 2000\\SG-Besprechungen\\Migration2015_Z.txt"

##QFile = r"R:\natura 2000\SG-Besprechungen\Migration2015_Q.txt"

##ZFile = r"R:\natura 2000\SG-Besprechungen\Migration2015_Z.txt"

f = open(QFile, 'r')

for line in f:

    print(line)

    # print f.readline

    f1 = open(ZFile, 'r')

    for line1 in f1:

        print(line1)

        shutil.move(line.strip(), line1.strip())

View solution in original post

0 Kudos
1 Reply
JohannesBierer
Frequent Contributor

strip() was the solution ...

import shutil, os, sys

# import numpy as np

QFile = "R:\\natura 2000\\SG-Besprechungen\\Migration2015_Q_Test.txt"

ZFile = "R:\\natura 2000\\SG-Besprechungen\\Migration2015_Z.txt"

##QFile = r"R:\natura 2000\SG-Besprechungen\Migration2015_Q.txt"

##ZFile = r"R:\natura 2000\SG-Besprechungen\Migration2015_Z.txt"

f = open(QFile, 'r')

for line in f:

    print(line)

    # print f.readline

    f1 = open(ZFile, 'r')

    for line1 in f1:

        print(line1)

        shutil.move(line.strip(), line1.strip())

0 Kudos