简体   繁体   English

如何复制文件,然后使用python将其保存为动态文件名

[英]How to copy a file and then save it with a dynamic filename using python

Example: I am taking a name from user, lets say: 例子:我从用户那里取一个名字,可以这样说:

domainName = input("Enter domain name:") domainName = input(“输入域名:”)

os.system(cp etc/default etc/domainName) os.system(cp等/默认等/域名)

Here the file will be copied with the name domainName but I want to save it with a name that is stored in variable domainName ? 在这里,文件将被复制为名称domainName,但是我想使用存储在变量domainName中的名称来保存它? How do I do this ? 我该怎么做呢 ?

Disclaimer: I don't recommend using os.system to copy files. 免责声明:我不建议使用os.system复制文件。 That said... 那个...

How about string concatenation? 字符串串联怎么样?

os.system("cp etc/default etc/" + domainName) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在python中基于部分文件名复制文件 - How to copy file based on partial filename in python 带有Unicode文件名的Python复制文件 - Python Copy file with unicode filename 如何获取要打开的文件的文件名和要保存在python中的文件的文件名 - How do I get the filename of a file to open and the filename of a file to save in python 复制python中文件名中具有特定字符串的文件 - Copy a file with a certain string in the filename in python 将文件复制到新位置并递增文件名,python - Copy a file to a new location and increment filename, python Python scp复制文件,文件名中带有空格 - Python scp copy file with spaces in filename 使用日期时间作为文件名在python中保存一个csv文件 - Save a csv file in python with datetime as filename 使用 Python 发送文件和文件名 - Send the file and the filename using Python 使用 Python Paramiko 通过 ssh/sftp 将文件复制到具有不同文件名的服务器 - Copy a file to server with a different filename using Python Paramiko over ssh/sftp 蟒蛇; 如何替换字符串模式并保存到文件中,如何使用字符串变量将文件名从文件夹名重命名为文件名? - Python; how to replace string pattern and save to a file, rename the file by string variable from folder name to the filename?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM