Hi Guys,
Thanks to answers, i'm using Windows OS.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Autor: Hugo Baur [email protected]
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import os.path
import shutil
from datetime import date
now = date.today()
#FILENAME = "E:/ENEL/Modelos/DC201609/DC201609-sem1/DADGER.rv0"
WORD = "& NO. SEMANAS NO MES INIC. DO ESTUDO=> 5"
#-------------------------FUNÇÕES--------------------------------
def criarPastaDestino(): # FUNÇÃO PARA CRIAR A PASTA RECIPIENTE , CRIAR AS SUB PASTAS E COPIAR SEU CONTEUDO
os.mkdir(directoryPath)
for x in range(0, int(meses)):
if x <= 9:
aux = (directoryPath + "DC" + str(now.year) + "0" + str(int(iniMes) + x) + "/")
# os.mkdir(aux)
numeroSemanas = find_word_in_file(origem + "/DADGER.rv0", WORD)
teste = numeroSemanas.replace('& NO. SEMANAS NO MES INIC. DO ESTUDO=> ', '')
if x < 1:
os.mkdir(aux)
for i in range(1, int(teste)-2):
a =str(x)
b = str(i)
#os.mkdir (aux + "DC" + str(now.year) + str(int(iniMes)) + "-sem" + b)
#os.mkdir (aux + "Relatorio_Sumario-" + "DC" + str(now.year) + str(int(iniMes))+ "-sem" + b)
if x <= 9:
criarpastas = (aux + "DC" + str(now.year) + "0" + str(int(iniMes) + x) + "-sem" + b)
criarpastasrelatorio = (aux + "Relatorio_Sumario-" + "DC" + str(now.year) + "0" + str(int(iniMes) + x) + "-sem" + b)
else:
criarpastas = (aux + "DC" + str(now.year) + str(int(iniMes) + x) + "-sem" + b)
criarpastasrelatorio = (aux + "Relatorio_Sumario-" + "DC" + str(now.year) + str(int(iniMes) + x) + "-sem" + b)
shutil.copytree(origem, criarpastas + "/")
shutil.copytree(origem, criarpastasrelatorio + "/")
# ALTERAR EXTENSÃO DE ARQUIVOS
os.rename(criarpastas + "/"+ "DADGNL.RV0", criarpastas + "/"+ "DADGNL.RV" + str(i-1))
os.rename(criarpastas + "/"+ "DADGER.RV0", criarpastas + "/"+ "DADGER.RV" + str(i-1))
os.rename(criarpastas + "/"+ "PREVS.RV0", criarpastas + "/"+ "PREVS.RV" + str(i-1))
os.rename(criarpastas + "/"+ "RV0.dat", criarpastas + "/"+ "RV" + str(i-1) +".dat")
os.rename(criarpastas + "/"+ "VAZOES.RV0", criarpastas + "/"+ "VAZOES.RV" + str(i-1))
os.rename(criarpastasrelatorio + "/"+"DADGNL.RV0", criarpastasrelatorio + "/"+ "DADGNL.RV" + str(i-1))
os.rename(criarpastasrelatorio + "/"+"DADGER.RV0", criarpastasrelatorio + "/"+ "DADGER.RV" + str(i-1))
os.rename(criarpastasrelatorio + "/"+"PREVS.RV0", criarpastasrelatorio + "/"+ "PREVS.RV" + str(i-1))
os.rename(criarpastasrelatorio + "/"+"RV0.dat", criarpastasrelatorio + "/"+ "RV" + str(i-1) +".dat")
os.rename(criarpastasrelatorio + "/"+ "VAZOES.RV0", criarpastasrelatorio + "/"+ "VAZOES.RV" + str(i-1))
# E:/ENEL/Modelos/DC201609/DC201609-sem1
# C:/TESTESISTEMA
# E:/ENEL/Modelos/NW201610
else:
if (int(iniMes) + x) <= 9: #8 9 12
aux = (directoryPath + "DC" + str(now.year) + "0" + str(int(iniMes) + x) + "/")
else:
if (int(iniMes) + x) > 9 and x < 12:
aux = (directoryPath + "DC" + str(now.year) + str(int(iniMes) + x) + "/")
else:
if (int(iniMes) + x) >= 12 and x < 21:
aux = (directoryPath + "DC" + str(now.year + 1) + "0" + str(int(iniMes) + x - 12) + "/")
else:
if (int(iniMes) + x) >= 21 and x < 24:
aux = (directoryPath + "DC" + str(now.year + 1) + str(int(iniMes) + x - 12) + "/")
else:
if (int(iniMes) + x) >= 24 and x < 33:
aux = (directoryPath + "DC" + str(now.year + 2) + "0" + str(int(iniMes) + x - 24) + "/")
else:
if (int(iniMes) + x) >= 33 and x < 36:
aux = (directoryPath + "DC" + str(now.year + 2) + str(int(iniMes) + x - 24) + "/")
else:
if (int(iniMes) + x) >= 36 and x < 45:
aux = (directoryPath + "DC" + str(now.year + 3) + "0" + str(int(iniMes) + x - 36) + "/")
else:
if (int(iniMes) + x) >= 45 and x < 48:
aux = (directoryPath + "DC" + str(now.year + 3) + str(int(iniMes) + x - 36) + "/")
else:
if (int(iniMes) + x) >= 48 and x < 57: #44 45 48
aux = (directoryPath + "DC" + str(now.year + 4) + "0" + str(int(iniMes) + x - 48) + "/")
else:
if (int(iniMes) + x) >= 57 and x < 60: #56 57 60
aux = (directoryPath + "DC" + str(now.year + 4) + str(int(iniMes) + x - 48) + "/")
shutil.copytree(origem, aux + "/")
# FUNÇÃO LOCALIZA A STRING "& NO. SEMANAS NO MES INIC. DO ESTUDO=> 5" E RETORNA O NUEMRO DE SEMANAS
def find_word_in_file(FILENAME, WORD):
f = open(FILENAME, "r")
file_array = f.readlines()
f.close()
for i in file_array:
if i.find(WORD) >= 0:
print("Localizado a string: " + i)
return i
return False
def newave_creator():
if int(now.month) <= 9:
path = (destino + "/" + "NW" + str(now.year) + "0" + str(int(now.month)) + "/")
else:
path = (destino + "/" + "NW" + str(now.year) + str(int(now.month)) + "/")
shutil.copytree(origemNewave, path)
print ("\n\n### Arquivos NEWAVE criados com sucesso! ###\n")
#-------------------------MENU-----------------------------------
digito = True
while digito:
print("""
1.Gerar dados para o modelo DCOMP
2.Gerar dados para o modelo NEWAVE
3.Opção 3
4.Exit/Quit
""")
digito = input("O que gostaria de fazer? ")
if digito == "1":
print("\nModelo DECOMP")
origem = input("Digite o caminho da ORIGEM dos dados: ") # DEFINE O PATH ORIGEM
nomedapasta = input("Digite o nome da pasta que será criada: ") # DEFINE O NOME DA PASTA A SER CRIADA
destino = input("Digite o caminho DESTINO dos dados: ") # DEFINE O PATH DE DESTINO
meses = input("Digite o numero de meses: ") # RECEBE O NUMERO DE MESES DE ESTUDO
iniMes = input("Digite o mês de início: ") # RECEBE O INICIO DE MESES DE ESTUDO
directoryPath = (destino + "/" + nomedapasta + "/") # PEGAR O DESTINO E CONCATENAR COM O NOME ESCOLHIDO DA PASTA PELO USUÁRIO
print("\n Você inseriu o caminho ORIGEM: " + origem + " e caminho DESTINO: " + directoryPath) # INFORMA AO USUÁRIO O PATH ORIGEM E O DESTINO
criarPastaDestino()
print("\n\n ## CRIAÇÃO BEM SUCEDIDA ##\n")
print("__________________________________________________________________")
elif digito == "2":
print("\nModelo NEWAVE")
origemNewave = input("Digite o caminho da ORIGEM dos dados: ") # DEFINE O PATH ORIGEM
destino = input("Digite o caminho DESTINO dos dados: ") # DEFINE O PATH DE DESTINO
newave_creator()
print ("__________________________________________________________________")
elif digito == "3":
path = input("Digite o caminho da ORIGEM dos dados: ") # DEFINE O PATH ORIGEM
numeroSemanas = find_word_in_file(path + "/DADGER.rv0", WORD)
teste = numeroSemanas.replace('& NO. SEMANAS NO MES INIC. DO ESTUDO=> ', '')
print("Número de semanas lido: " + teste + "O número de semanas que será criado: " + str(int(teste) - 2))
elif digito == "4":
print("\n### OBRIGADO, TENHA UM BOM DIA! ###")
digito = None
else:
print("\n#### Digito inválido, por favor digite um dos números do menu. ###")
So, to replices that, you need archives .txt, just 2.
one with the name "DADGER.rv0" containing the string "& NO. SEMANAS NO MES INIC. DO ESTUDO=> 5" and another with any name and any content, only for viewing.
First - Put de path od the first archive
Second - Name of the new archive
third - Path where the new files will be created
fourth - Number of the months
fifth - Number of the initial month
If you start using a initial month, its ok. Works!
if you start with the month 10 for example, doesn't work.