1
A
回答
2
此功能由迈克尔蟒蛇2.7:
from smb.SMBConnection import SMBConnection
dry_run = True # Set to True to test if all files/folders can be "walked". Set to False to perform the deletion.
userID = 'myuser'
password = 'mypassword'
client_machine_name = 'testclient' # Usually safe to use 'testclient'
server_name = 'MYSERVER' # Must match the NetBIOS name of the remote server
server_ip = '192.168.1.10' # Must point to the correct IP address
domain_name = '' # Safe to leave blank, or fill in the domain used for your remote server
shared_folder = 'smbtest' # Set to the shared folder name
conn = SMBConnection(userID, password, client_machine_name, server_name, domain=domain_name, use_ntlm_v2=True, is_direct_tcp=True)
conn.connect(server_ip, 445)
def walk_path(path):
print 'Walking path', path
for p in conn.listPath(shared_folder, path):
if p.filename!='.' and p.filename!='..':
parentPath = path
if not parentPath.endswith('/'):
parentPath += '/'
if p.isDirectory:
walk_path(parentPath+p.filename)
print 'Deleting folder (%s) in %s' % (p.filename, path)
if not dry_run:
conn.deleteDirectory('smbtest', parentPath+p.filename)
else:
print 'Deleting file (%s) in %s' % (p.filename, path)
if not dry_run:
conn.deleteFiles('smbtest', parentPath+p.filename)
# Start and delete everything at shared folder root
walk_path('/')
相关问题
- 1. 删除文件夹/文件和子文件夹
- 2. 如何删除文件,主文件夹和子文件夹
- 3. 从文件夹和子文件夹中删除文件
- 4. 如何递归删除文件夹?
- 5. Gulp - 递归删除空文件夹
- 6. SFTP非空文件夹递归删除
- 7. 使用Delphi递归删除所有文件和文件夹
- 8. 删除许多文件夹和子文件夹中的特定文件夹
- 9. 枚举文件和文件夹递归
- 10. 递归文件夹
- 11. 用文件夹中的文件删除文件和子文件夹
- 12. htaccess删除文件夹的文件夹
- 13. 递归地tar'ing主文件夹的子文件夹
- 14. Python的递归找到文件夹或子文件夹
- 15. 删除批处理文件夹中的文件和文件夹
- 16. 删除指定文件夹中的文件和文件夹
- 17. 删除文件和程序文件夹的文件夹
- 18. 删除文件夹“tmp”和“cache”中的文件和子文件夹
- 19. 删除文件夹和子文件夹如果不使用(Powershell)
- 20. python删除所有文件(递归)没有文件夹本身
- 21. 清除文件夹 - 删除文件夹中的文件 - J2ME
- 22. 在linux上删除包含子文件夹和文件的文件夹
- 23. 删除文件夹和包含文件
- 24. 删除文件和文件夹问题
- 25. C#的文件夹和子文件夹
- 26. .htaccess重定向文件夹和子文件夹,除了一些子文件夹
- 27. 的mod_rewrite删除子文件夹和PHP
- 28. VB脚本从文件夹中删除子文件夹和文件
- 29. 使该文件夹中的文件夹和子文件夹
- 30. 删除文件夹和所有子文件夹(包括文件夹)中的所有文件