directory-tree

Get directory structure from FTP using PHP

偶尔善良 提交于 2021-02-08 09:20:08
问题 I have ftp server with a lot of subfolders and files in it. I need to retrieve the folder structure from ftp, which shows names of all folders and subfolders from a specified starting path. I'm not interested in files included in each folder, only the directory tree. I'm using PHP and my server does not support mlsd. Thanks for help. I implemented my own recursive function, which for some reason is not working. function ftp_list_files_recursive($ftp_stream, $path) { $lines = ftp_rawlist($ftp

How can I create directory tree in C?

家住魔仙堡 提交于 2020-06-28 09:16:16
问题 I want an easy way to create multiple directories in C. For example I want to create directory in: /a/b/c but if the directories are not there I want them to be created automagically. How can I do this ? 回答1: Here is a small C program to create the directory tree a/b/c in the current directory: #include <stdio.h> #include <stdlib.h> #include <sys/stat.h> #include <errno.h> int create_dir(char *name) { int rc; rc = mkdir(name, S_IRWXU); if (rc != 0 && errno != EEXIST) { perror("mkdir"); exit(1

How can I create directory tree in C?

时光毁灭记忆、已成空白 提交于 2020-06-28 09:15:00
问题 I want an easy way to create multiple directories in C. For example I want to create directory in: /a/b/c but if the directories are not there I want them to be created automagically. How can I do this ? 回答1: Here is a small C program to create the directory tree a/b/c in the current directory: #include <stdio.h> #include <stdlib.h> #include <sys/stat.h> #include <errno.h> int create_dir(char *name) { int rc; rc = mkdir(name, S_IRWXU); if (rc != 0 && errno != EEXIST) { perror("mkdir"); exit(1

Representing a directory tree as a recursive list

我与影子孤独终老i 提交于 2020-01-03 08:36:07
问题 I am stuck with a certain task. What I want is a function that, given a directory path, would return a recursive-list as an output. The output should be of the form myList$dir$subdir$subdir$fullFilePath So basically I want to represent a directory tree as a certain list. I obtain all the files, get all the subdirectories for each of the file, but I am stuck as to how to throw it all into a list with multiple levels. 回答1: Here is a solution using recursion: tree.list <- function(file.or.dir) {

Directory-tree listing in Python

余生颓废 提交于 2019-12-27 08:56:47
问题 How do I get a list of all files (and directories) in a given directory in Python? 回答1: This is a way to traverse every file and directory in a directory tree: import os for dirname, dirnames, filenames in os.walk('.'): # print path to all subdirectories first. for subdirname in dirnames: print(os.path.join(dirname, subdirname)) # print path to all filenames. for filename in filenames: print(os.path.join(dirname, filename)) # Advanced usage: # editing the 'dirnames' list will stop os.walk()

in bash find all files in flat directory that don't exist in another directory tree

不打扰是莪最后的温柔 提交于 2019-12-10 10:20:53
问题 I have many files in a directory A . Some of those files exist in a directory tree with sub-directories B/B1 , B/B2 , B/B3 , B/B4 , ... Note that some files have spaces in their names. For example: in directory A : there's a file named A/red file.png there's another named A/blue file.png and, in directory tree B : there's a file named B/small/red file.png In this example, I would like a script to tell me that the file blue file.png does not exist in the directory B . How can I write a script

in bash find all files in flat directory that don't exist in another directory tree

老子叫甜甜 提交于 2019-12-05 23:21:04
I have many files in a directory A . Some of those files exist in a directory tree with sub-directories B/B1 , B/B2 , B/B3 , B/B4 , ... Note that some files have spaces in their names. For example: in directory A : there's a file named A/red file.png there's another named A/blue file.png and, in directory tree B : there's a file named B/small/red file.png In this example, I would like a script to tell me that the file blue file.png does not exist in the directory B . How can I write a script that will list all the files in A that are not found under the directory tree B ? # A # ├── blue file

How to create a zip archive of a directory in Python?

﹥>﹥吖頭↗ 提交于 2019-11-25 23:39:14
问题 How can I create a zip archive of a directory structure in Python? 回答1: As others have pointed out, you should use zipfile. The documentation tells you what functions are available, but doesn't really explain how you can use them to zip an entire directory. I think it's easiest to explain with some example code: #!/usr/bin/env python import os import zipfile def zipdir(path, ziph): # ziph is zipfile handle for root, dirs, files in os.walk(path): for file in files: ziph.write(os.path.join(root