python如何创建工程文件夹,如何将现有文件夹结构添加到我的Visual Studio项目(Python工具)?...

This question is essentially the same as these:

Except the solutions don't work for me.

It looks like another user had the exact same problem

But http://xkcd.com/979/ has struck again.

I am using Visual Studio 2010 with Python Tools for Visual Studio.

In this project users create new folders and code and commit them to SVN. Another user will update SVN and the new files and folders will show up in windows explorer. The user then needs an easy way to add these folders and files to the solution.

Putting the solution in SVN so added folders can be added to the solution before committing is not an option. The solution is controlled in a separate area from the source.

Suggested Solution:

Won't work because:

The "Show all files" button in the solution explorer does not show up.

Suggested Solution:

Won't work because:

When I drag the folder onto the solution explorer pane the location the folder is dropped affects where in the solution it is nested. If it gets dropped in the wrong folder, it shows up as a folder with the expected name and the expected contents. This is really close to what we want, except its in the wrong folder (since I dropped it on the wrong folder, intentionally). If the folder is dragged to the correct location, it appears as a file with an exclamation point. When you double click the "file" it says

"The item does not exist in the project directory. It may have been moved, renamed, or deleted"

I believe this is because VS will try to create a copy of the folder in the directory that you drag it to. If I move the folder out of my project entirely (say to the desktop) and then drag it into the solution explorer at the proper location, it shows up as a folder in the project. A copy of the folder is also created on disk at the location specified by the drop, with the same name and contents.

So it appears that dragging and dropping a folder onto the solution explorer will create a copy of the folder on the disk in the location that you targeted in your solution when you dropped it. If that location already has a folder of that name, the folder gets imported as a file.

My Solution

I'm using PyCharm instead, its much better.

解决方案

If nothing else works, you could add the files and folders manually in the .pyproj-file. The format is simple:

You can add more elements if you want, and you can mix files and folder if you wish.

Script to generate the XML:

import os

def visit(folder):

for fn in os.listdir(folder):

filename = os.path.join(folder, fn)

_, ext = os.path.splitext(fn)

if os.isdir(filename):

folders.append(filename)

visit(filename)

elif ext.lower() == '.py':

files.append(filename)

files = []

folders = []

visit('.')

print ''

for fn in files:

print ' '

print ''

if folders:

print ''

for fn in folders:

print ' '

print ''

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值