Can't get into a directory - python-3.x

for file in os.listdir(r'C:\Users\user\Downloads\plant_tomato_leaf_dataset\plantvillage'):
for cl in os.listdir(r'C:\Users\user\Downloads\plant_tomato_leaf_dataset\plantvillage\\'+file):
print(file)
print(cl)
print('******************')
I have a folder "plantvillage". Inside that folder I have 10 folder. I have to access all the sub-folders and perform operations on those sub-folder-items. But this code is showing only items of the first folder

You might be interested in os.walk instead of os.listdir. listdir is not recursive.
An example would be:
for root, dirs, files in os.walk(r'C:\Users\user\Downloads\plant_tomato_leaf_dataset\plantvillage'):
for file in files:
print(os.path.join(root,file))
this will run the inner loop as many times as there are directories, and will also check to make sure that each file is actually a file. If you want to look at the directories themselves for some reason (ignoring files), you can do that like so:
for root, dirs, files in os.walk(r'C:\Users\user\Downloads\plant_tomato_leaf_dataset\plantvillage'):
for directory in dirs:
print(os.path.join(root,directory))
but don't try to mix and match. Getting the current directory is easy when iterating files. It's just root.

Related

Perforce ignore subdirectories with p4ignore

I have a .p4ignore file and it does the job for the most part but I am trying to ignore certain subfolders but it does not seem to work.
# Ignore .meta, csproj files at the moment
*.meta
.DS_Store
# Ignore these folders
Data
Library
obj
# Ignore these subfolders
Resources/Subfolder1
Resources/Subfolder2
The resources folder is in the same directory as the .p4ignore yet it still checks out Subfolder1 and Subfolder2 into the changelist. It ignores Data, Library and obj. What am I missing?
In my experience, you need to append /** in order to get Perforce to ignore the contents of a directory, so in your example:
Resources/Subfolder1/**
Resources/Subfolder2/**

Remove .svn files from zip file

I would like to remove all svn directories from a zip file. Can not find correct pattern. This is the pattern I tried ".svn/*"
Was able to remove all .class files.
Found pattern. Should work for any directory.
"/.svn/"
Avoid the problem in the first place. Don't create your zip file directly from your working copy. Just use svn export to create a new directory without the .svn directories, and without any unversioned files, and zip that instead.

shell rsync: recursively merging filter files

I have a filter file '.filter' for rsync with the following contents:
merge '../.pattern'
The included file '.pattern' in turn also includes other pattern file in its parent directory and has the same contents:
merge '../.pattern'
When files are included in such a way, rsync apparently goes in infinite recursion and exits with "too many open files" error. Is there a way with rsync to use multiple levels of included files with relative paths?

Find files in not readable directory LINUX

How to find all files in non readable directory
For example directory /home is locked perm 40700
But I can read all files in this directory like
/home/index.php and etc
How to list all files in this directory?
I tryed ls and find function do not want to find thoose files
The r permission of folders determines whether you can list the contents. If a folder has x but not r, then you can access files as long as you know their names.
An example for this is to allow users to publish HTML documents in their home folders. For this, set the permissions for /home/user to rwx-----x and /home/user/public_html to rwx---r-x
That way, the HTML server can access the folder (it can walk though your home folder) but it can't see any files outside of the public_html folder.

Not symlinking one or two files inside symlinked directory

Is there a way not to symlink one or two files within a symlinked directory in CentOS?
I've got the entire directory symlinked but there are two css files that I would like to use the current copy for the website
In short: no.
Another way to do this would be to symlink all the files in that directory, except those you want local copy of.
Still another way to go might be using unionfs or aufs to union-mount the original directory and a directory containing the files you need local, with the directory containing local files being "on top".
Say, your original directory is orig, the directory with files that should be local is local, the union directory is union, and you want files from both directories to be writable. Then you can union-mount them like this:
unionfs-fuse local=RW:orig=RW union
And unmount like this:
fusermount -u union
See unionfs manpage (unionfs-fuse(8) at least on Debian) for details.

Resources