A
A
Alexander Shilov2018-10-30 08:47:29
Python
Alexander Shilov, 2018-10-30 08:47:29

How to rename files in Python with os.rename() method?

There is the following code, which works well and stably, but line 28
os.rename(name_files, name_new_files)
does not want to work, tell me, maybe I misunderstand something somewhere. Everything works fine without this line.

import time
import xlrd
import os

num = 0
print('Перенесите сюда файл:')
book = xlrd.open_workbook(input())
print('Число рабочих листов {0}'.format(book.nsheets))
k = book.sheet_names()
for i in k:
  print(num, ' - ', k[num])
  num+=1
print('Выберите имя рабочего листа:')
ind = input()
sheet = book.sheet_by_name('{}'.format(ind))
print('Вы выбрали лист {0} в котором {1} строк и {2} столбцов'.format(sheet.name, sheet.nrows, sheet.ncols))
print('Выберите номер строки, с которой начнем считывание')
number = input()
print('Перенесите сюда папку, откуда мы с Вами будем брать Скриншоты :)')
link_of_folder = input()
os.chdir(link_of_folder)
j=0
number_end = sheet.nrows
for number in range(number_end):
  print('{1} - {0}'.format(sheet.cell_value(number, 0), sheet.cell_value(number, 50)))
  name_files = '{}.jpg'.format(sheet.cell_value(number, 50))
  name_new_files = '{}.jpg'.format(sheet.cell_value(number, 0))
  os.rename(name_files, name_new_files)
  j+=1
print(j)
time.sleep(5000)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question