小编fel*_*yot的帖子

从FTP返回文件树

我试图从FTP服务器列出文件.我希望将一个子目录和文件数组作为树来获取,如下所示:

folder1
       file1.txt
       file2.txt
folder2
       folder2a
               file1.txt
               file2.txt
               file.3txt
       folder2b
              file1.txt
Run Code Online (Sandbox Code Playgroud)

现在我的数组将是类似的

[folder1]=>array(file1.txt,file2.txt) 
[folder2]=>array([folder2a]=>array(file1.txt,file2txt,file3.txt)
[folder2b]=>array(file1.txt))
Run Code Online (Sandbox Code Playgroud)

注意:上面的数组可能不是确切的语法,只是为了让我知道我在寻找什么.我试过ftp_nlist()但似乎只返回文件和文件夹,但不返回子文件夹中的文件.以下是我的代码如何显示的示例

 // set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// get contents of the ftp directory
$contents = ftp_nlist($conn_id, ".");

// output $contents
var_dump($contents);
Run Code Online (Sandbox Code Playgroud)

以上只有文件夹列表而不是文件列表.任何人都知道如何解决这个问题?谢谢.

php ftp web-applications file

3
推荐指数
1
解决办法
8536
查看次数

如何创建对形式的python字典键

例如,我有一个字典词典

my_dictionary= {'a': 20, 'c': 60, 'b': 10}
Run Code Online (Sandbox Code Playgroud)

在这种情况下,我有来自字典的3个键.我想制作对并将它们作为元组存储在列表中.对于上述情况,我会有这个

[(a,b),(a,c),(b,c)]
Run Code Online (Sandbox Code Playgroud)

注意:不重复.

在没有使用任何外部模块的情况下,最好的方法是什么.

谢谢你的贡献.

python algorithm dictionary list

0
推荐指数
1
解决办法
159
查看次数

标签 统计

algorithm ×1

dictionary ×1

file ×1

ftp ×1

list ×1

php ×1

python ×1

web-applications ×1