如何重命名文件并更改文件类型?
我有一个包含 .dbf
文件的列表,我想将其更改为 .csv
文件。我手动在 Excel 中打开它们并将它们重新保存为 .csv
,但这需要太多时间。
现在我制作了一个更改文件名的脚本,但是当我打开它时,它仍然是 .dbf
文件类型(尽管它被称为 .csv
)。如何重命名文件以使文件类型也发生变化?
我的脚本使用(dbf 和 csv 文件名列在单独的 csv 文件中):
IN = dbffile name
OUT = csvfile name
for output_line in lstRename:
shutil.copyfile(IN,OUT)
I have a list with .dbf
files which I want to change to .csv
files. By hand I open them in excel and re-save them as .csv
, but this takes too much time.
Now I made a script which changes the file name, but when I open it, it is still a .dbf
file type (although it is called .csv
). How can I rename the files in such a way that the file type also changes?
My script uses (the dbf and csv file name are listed in a seperate csv file):
IN = dbffile name
OUT = csvfile name
for output_line in lstRename:
shutil.copyfile(IN,OUT)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
更改文件名(扩展名只是完整名称的一部分)对文件的内容绝对没有影响。您需要以某种方式将内容从一种格式转换为另一种格式。
使用我的dbf模块和python 这非常简单:
这将创建一个实际上是 csv 格式的
.csv
文件。Changing the name of a file (and the extension is just part of the complete name) has absolutely no effect on the contents of the file. You need to somehow convert the contents from one format to the other.
Using my dbf module and python it is quite simple:
This will create a
.csv
file that is actually in csv format.如果您曾经使用过 VB 或研究过 VBA,您可以编写一个简单的 Excel 脚本来打开每个文件,将其另存为 csv,然后使用新名称保存。
使用宏录制器录制您自己执行的操作,然后编辑生成的脚本。
我现在创建了一个自动执行此操作的应用程序。它称为 xlsto (查找 xls.exe 发布文件)。它允许您选择一个文件夹并将所有 xls 文件转换为 csv(或任何其他类型)。
If you have ever used VB or looked into VBA, you can write a simple excel script to open each file, save it as csv and then save it with a new name.
Use the macro recorder to record you once doing it yourself and then edit the resulting script.
I have now created a application that automates this. Its called xlsto (look for the xls.exe release file). It allows you to pick a folder and convert all xls files to csv (or any other type).
您需要转换器
搜索
dbf2csv 在谷歌中。
You need a converter
Search for
dbf2csv
in google.这取决于你想做什么。您似乎想将文件转换为其他类型。那里有很多转换器,但仅靠计算机并不能识别每种文件类型。为此,您需要下载一些软件。如果您只想更改文件扩展名,
(例如 .png、.doc、.wav)然后您可以将计算机设置为能够更改名称和扩展名。我希望我能以某种方式提供帮助:)
It depends what you want to do. It seems like you want to convert files to other types. There are many converters out there, but a computer alone doesn't know every file type. For that you will need to download some software. If all you want to do is change the file extension,
(ex. .png, .doc, .wav) then you can set your computer to be able to change both the name and the extension. I hoped I helped in some way :)
下载 libreria dbfpy desde http://sourceforge.net/projects/dbfpy/?source=dlp
descargar libreria dbfpy desde http://sourceforge.net/projects/dbfpy/?source=dlp
新文件名可能是“xzy.csv.dbf”。通常在 C# 中我在文件名中添加引号。这会强制操作系统更改文件名。尝试使用引号中的“Xzy.csv”之类的内容。
It might be that the new file name is "xzy.csv.dbf". Usually in C# I put quotes in the filename. This forces the OS to change the filename. Try something like "Xzy.csv" in quotes.