Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
concatenat - shutil
#1
import shutil
t1 = 'bjjj'
t2 = 4455
t3 = '.txt'
t6 = print(t1+str(t2)+t3)
shutil.copy('bjjj.txt', 't6')
shutil.copy('bjjj.txt', 'bjjj4455.txt')

NOTE NOTE
I have a job file called bjjj.txt. When the program ended, I wanted it to be copied to the same name concatenated with a variable. I made immense attempts to no avail. If you put fixed bjjj4455.txt it works perfectly. But I want to increase the number 4455 +1 ...
Thank you
buran write Feb-11-2021, 11:57 AM:
Please, use proper tags when post code, traceback, output, etc. You have been advised to do so.
See BBcode help for more info.
Reply
#2
Is this what your are looking for?

prefix = 'bjjj'
version_number = 4455
version_number += 1
sufix = '.txt'
new_file_name = f'{prefix}{version_number}{sufix}'
shutil.copy('bjjj.txt', new_file_name)
or condensed:

new_file_name = f'bjjj{version_number}.txt'
Reply
#3
Smile Smile Smile Smile Smile Smile Smile Heart
thank you. what should I do to complete this request of mine. Worked perfectly. thanks again
Reply
#4
(Feb-10-2021, 11:21 PM)BashBedlam Wrote: Is this what your are looking for?

prefix = 'bjjj'
version_number = 4455
version_number += 1
sufix = '.txt'
new_file_name = f'{prefix}{version_number}{sufix}'
shutil.copy('bjjj.txt', new_file_name)
or condensed:

new_file_name = f'bjjj{version_number}.txt'
NOTE NOITE
100% sorted out Dance LOL

I have a problem to finalize the program for the post subject "goto". there is a line in the "for _ in range (1)" cycle that says
"print (f '{k} EXISTS')" must go back to for _, as this number that exists should not be announced. please, can you help me?! In the hands of a good programmer, it should be easy. Do you have access to my GOTO order?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  use of shutil.copytree with ENOTDIR exception yan 2 918 Nov-29-2023, 03:02 PM
Last Post: yan
  shutil.move make data corrupt kucingkembar 0 801 Feb-01-2023, 01:30 PM
Last Post: kucingkembar
  Merge htm files with shutil library (TypeError: 'module' object is not callable) Melcu54 5 1,606 Aug-28-2022, 07:11 AM
Last Post: Melcu54
  extra slashes in the network path for shutil.copy tester_V 3 3,784 Jun-02-2021, 07:57 AM
Last Post: supuflounder
  Shutil FileNotFoundError: Errno 2 Help lord_kaiser 8 10,556 Aug-10-2020, 08:45 AM
Last Post: lord_kaiser
  shutil.copy questions kristianpython 3 2,328 Jul-14-2020, 09:19 AM
Last Post: Gribouillis
  Shutil move if file exists in destination Friend 2 6,782 Feb-02-2020, 01:45 PM
Last Post: Friend
  Shutil attempts to copy directories that don't exist ConsoleGeek 5 4,566 Oct-29-2019, 09:26 PM
Last Post: Gribouillis
  Help copying files with shutil hikerguy62 2 4,314 Aug-02-2019, 08:16 PM
Last Post: hikerguy62
  Shutil - permission error equaliser 1 6,258 Dec-07-2018, 05:11 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020