#๐ how to copy the same file over to a destination path
13 messages ยท Page 1 of 1 (latest)
@austere barn
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
import random
import shutil
number_of_people = int(input("How many people are there?"))
list_of_stuff = []
stuff_to_add = list(range(1,69))
for i in range (number_of_people)
random.shuffle(stuff_to_add)
source_path = rf"C:\blah blah file path\{stuff_to_add[0]}.file"
destination_path = rf"C:\blah blah file path 2"
shutil.copy(source_path, destination_path)
list_of_stuff.append(stuff_to_add[0])
print(list_of_stuff)
lets say the number 42 is shuffled and put as position 0 in "stuff_to_add" multiple times
how can i copy multiple of said file into the destination path?
would i have to get the code to rename the file copied or what is the options here?
going to step away for just a moment though so if i dont respond right away sorry
for n in range(2,20): # or something to pick the numbers to try
copy(original_filename, f'{dest_dirpath}/{some_filename}{n}')
or some suitable variation on that.
You can precheck if the file exists with os.path.exists to avoid tromping things. You'd need a precheck if eg you used shutil.copyfile for the copy, or if you're opening the new file yourself you can use the 'x' open mode, which will fail of the file exists.
sorry was finishing dinner
okay my brain is failing me tonight on this tbh, can i just ask this question tomororow lol
Probably provide more detail on what you're doing. Just copying files into a folder and renaming with a number to avoid conflicts? Something else?
Anyway, for then, not now.
gotcha, my full code is over 300 lines so i didnt want to paste all that when the issue is one paart but yeah
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.