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. 如何删除文件,主文件夹和子文件夹
- 6. PHP递归删除文件夹
- 7. SFTP非空文件夹递归删除
- 8. Gulp - 递归删除空文件夹
- 9. 如何递归删除文件夹?
- 10. 使用Delphi递归删除所有文件和文件夹
- 11. Git如何递归删除文件和文件夹?
- 12. 在Win32中删除子文件夹之前,如何从文件夹和子文件夹中删除文件?
- 13. 删除许多文件夹和子文件夹中的特定文件夹
- 14. 枚举文件和文件夹递归
- 15. 创建文件和文件夹递归
- 16. 递归文件夹
- 17. 用文件夹中的文件删除文件和子文件夹
- 18. 以递归方式删除文件夹时排除文件
- 19. htaccess删除文件夹的文件夹
- 20. 删除c中的文件夹和子文件夹#
- 21. 递归地tar'ing主文件夹的子文件夹
- 22. Python的递归找到文件夹或子文件夹
- 23. 删除批处理文件夹中的文件和文件夹
- 24. 删除文件和程序文件夹的文件夹
- 25. 删除指定文件夹中的文件和文件夹
- 26. 删除文件夹“tmp”和“cache”中的文件和子文件夹
- 27. 删除文件夹和子文件夹如果不使用(Powershell)
- 28. 如何删除子文件夹而不删除父文件夹和子文件夹?
- 29. 在Windows cmd上递归删除文件或文件夹
- 30. python删除所有文件(递归)没有文件夹本身