QTDir why not display all the folder in the root "/" in MacOs? - qt

I'm starting to use QT, and trying QDir I copy the example in the references of QT the one which listing the content of a folder.
I'm trying to listing the content of the root path in a MacOS snow leopard, version of QT 5.1.1 But don't appear all of it :S
This is the code:
QFileInfoList list = QDir::root().entryInfoList();
for(int i=0; i<list.count(); i++){
cout<< list[i].fileName().toStdString()<<endl;
}
But the output of this program is:
.
..
Applications
Developer
Library
opt
sockets.log
System
Users
When I think it should be:
I know that ls -l don't show . and .. my worry is about the other folders, I put a line break separating the folders that appears in the output and ones who don't.
$ ls -l /
drwxrwxr-x+ 63 root admin 2142 Sep 18 21:22 Applications
drwxrwxr-x# 15 root admin 510 Jan 1 2012 Developer
drwxrwxr-t+ 63 root admin 2142 Sep 16 13:05 Library
drwxr-xr-x 3 root admin 102 Jul 23 02:45 opt
-rw-rw-rw- 1 Andreu admin 75 Sep 19 12:35 sockets.log
drwxr-xr-x 4 root wheel 136 Sep 15 20:49 System
drwxr-xr-x 5 root admin 170 Sep 15 20:17 Users
drwxr-xr-x# 2 root wheel 68 Jun 23 2009 Network
drwxrwxrwt# 5 root admin 170 Sep 16 14:01 Volumes
drwxr-xr-x# 39 root wheel 1326 Sep 15 22:46 bin
drwxrwxr-t# 2 root admin 68 Jun 23 2009 cores
dr-xr-xr-x 3 root wheel 4272 Sep 16 13:26 dev
lrwxr-xr-x# 1 root wheel 11 Sep 15 20:04 etc -> private/etc
dr-xr-xr-x 2 root wheel 1 Sep 16 13:26 home
-rw-r--r--# 1 root wheel 20828964 Jun 8 2011 mach_kernel
dr-xr-xr-x 2 root wheel 1 Sep 16 13:26 net
drwxr-xr-x# 6 root wheel 204 Sep 15 20:08 private
drwxr-xr-x# 67 root wheel 2278 Sep 15 22:46 sbin
lrwxr-xr-x# 1 root wheel 11 Sep 15 20:04 tmp -> private/tmp
drwxr-xr-x# 14 root wheel 476 Sep 16 13:07 usr
lrwxr-xr-x# 1 root wheel 11 Sep 15 20:04 var -> private/var
Anyone can tell me why the other folders not appear?
Thanks :)

Add filter to entryInfoList
On Unix entryInfoList() does not list hidden files. You have to "ask" for them. I think it will be similiar on Mac.
QFileInfoList list = QDir::root().entryInfoList(QDir::AllEntries | QDir::System | QDir::Hidden);
for(int i=0; i<list.count(); i++){
cout<< list[i].fileName().toStdString()<<endl;
}

Related

Cron job indicates error - mv: cannot access <filename> but the files have moved

The logs for my cron job show the following:
Your "cron" job on
produced the following output:
mv: cannot access *SRP*
mv: cannot access 0001LO928365.CSE
...
and so on.
But the files did actually move to the desired location.
What might be causing this error? Any help is appreciated!
Apologies - I figured this one out.
The move command is looking for different file types and moving all types. Even if the file is present, the command outputs an error stating file not found.
See testing details below:
root#abcd-abcdef:~/movetest/out# ls -lrt
total 5
-rw-r--r-- 1 root root 0 Aug 20 13:53 testfile1.CSE
-rw-r--r-- 1 root root 0 Aug 20 13:53 testfile2.CSE
-rw-r--r-- 1 root root 0 Aug 20 13:53 testfile3.CSE
-rw-r--r-- 1 root root 0 Aug 20 13:53 testfile4.CSE
-rw-r--r-- 1 root root 0 Aug 20 13:53 testfile5.CSE
root#abcd-abcdef:~/movetest/out# cd ../archive
root#abcd-abcdef:~/movetest/archive# ls -lrt
total 0
root#abcd-abcdef:~/movetest/archive# cd -
/home/specuser/movetest/out
root#abcd-abcdef:~/movetest/out# mv *.SRP* *.CSE* *SRP* *CSE* *.xml* ../archive/
mv: cannot access *.SRP*
mv: cannot access *SRP*
mv: cannot access testfile1.CSE
mv: cannot access testfile2.CSE
mv: cannot access testfile3.CSE
mv: cannot access testfile4.CSE
mv: cannot access testfile5.CSE
mv: cannot access *.xml*
root#abcd-abcdef:~/movetest/out# ls -lrt
total 0
root#abcd-abcdef:~/movetest/out# cd -
/home/specuser/movetest/archive
root#abcd-abcdef:~/movetest/archive# ls -lrt
total 5
-rw-r--r-- 1 root root 0 Aug 20 13:53 testfile1.CSE
-rw-r--r-- 1 root root 0 Aug 20 13:53 testfile2.CSE
-rw-r--r-- 1 root root 0 Aug 20 13:53 testfile3.CSE
-rw-r--r-- 1 root root 0 Aug 20 13:53 testfile4.CSE
-rw-r--r-- 1 root root 0 Aug 20 13:53 testfile5.CSE
root#abcd-abcdef:~/movetest/archive#*

The Z shell returns "number expected" when I try to remove a directory

Why can't I delete this directory in the Z shell? What number is expected?
I have tried googling "number expected" and z shell to no avail.
drwxr-xr-x 3 me staff 96 Jan 31 09:49 PycharmProjects
drwxr-xr-x+ 3 me staff 96 Apr 21 2015 Sites
drwxr-xr-x# 13 me staff 416 Jul 1 2019 iCloud Drive (Archive)
drwx---rwx# 39 me staff 1248 Dec 5 12:28 iCloud Drive (Archive) 2
me#BigT ~ % rmdir -rf iCloud Drive (Archive)
**zsh: number expected**
My guess is the spaces and parenthesis are making ZSH try to expand / evaluate your expression, which is invalid. Try surrounding the name of the folder with quotes, like so:
rm -rf "iCloud Drive (Archive)"

What is the purpose of --file-type in ls command

I'm trying to understand the purpose of the --file-type argument of the UNIX ls command.
I didn't find any example using ls --file-type on the web – neither was I able to make sense of the --file-type argument by issuing ls --file-type myself.
What's the purpose of ls --file-type? Would anyone please give me a helpful example of ls --file-type making the purpose of this argument more clear to me?
Quoting from info ls:
-F
Append a character to each file name indicating the file type.
Also, for regular files that are executable, append *. The file
type indicators are / for directories, # for symbolic links,
| for FIFOs, = for sockets, > for doors, and nothing for
regular files.
--file-type is just like -F, except that it doesn't append * for executable files:
$ ln -s /etc/passwd foo
$ touch bar; chmod +x bar
$ ls
foo bar
$ ls -F
foo# bar*
$ ls --file-type
foo# bar
...
...
The --file-type option is similar to the -F option.
-F, --classify
append indicator (one of */=>#|) to entries
--file-type
likewise, except do not append `*'
Source.
Here's an example of ls --file-tye /
bin# boot/ dev/ etc/ home/ lib# lib64# lost+found/ media/ mnt/ opt/ proc/ root/ run/ sbin# srv/ sys/ tmp/ usr/ var/
as compared to the output of ls -l /
lrwxrwxrwx 1 root root 7 Jan 19 02:32 bin -> usr/bin
drwxr-xr-x 4 root root 4096 Jan 1 1970 boot
drwxr-xr-x 24 root root 4220 Mar 26 19:56 dev
drwxr-xr-x 88 root root 4096 Mar 26 21:15 etc
drwxr-xr-x 4 root root 4096 Apr 5 2020 home
lrwxrwxrwx 1 root root 7 Jan 19 02:32 lib -> usr/lib
lrwxrwxrwx 1 root root 7 Jan 19 02:32 lib64 -> usr/lib
drwx------ 2 root root 16384 Apr 5 2020 lost+found
drwxr-xr-x 2 root root 4096 Dec 11 20:19 media
drwxr-xr-x 7 root root 4096 Sep 8 2020 mnt
drwxr-xr-x 9 root root 4096 Feb 9 13:58 opt
dr-xr-xr-x 335 root root 0 Mar 26 19:56 proc
drwxr-x--- 9 root root 4096 Feb 11 13:18 root
drwxr-xr-x 28 root root 700 Mar 26 21:15 run
lrwxrwxrwx 1 root root 7 Jan 19 02:32 sbin -> usr/bin
drwxr-xr-x 4 root root 4096 Apr 5 2020 srv
dr-xr-xr-x 13 root root 0 Mar 26 19:56 sys
drwxrwxrwt 12 root root 320 Mar 26 22:11 tmp
drwxr-xr-x 9 root root 4096 Mar 25 11:06 usr
drwxr-xr-x 12 root root 4096 Mar 25 11:07 var
As you see the symbol "#" indicates symbolic-links (l). Directories (d) and regular files (f) are not flagged by the --file-type argument.
Issuing ls --file-type in my home directory is identical to ls ~ since it only contains directories and regular files and hence the output of the former doesn't contain any indicators.
See also the answer of PesaThe for a full list of the indicator symbols.

Rename files based on a list

I would like to rename all files in a folder based on a text file (list.txt) with two columns: oldnam (which represents the current name) and newnam (which contains the required new name).
My text file:
df <- "oldnam newnam
TRTY_3.DOT 124325.DOT
TRTY_4.DOT 123454.DOT
TRTY_5.DOT 124355.DOT"
df <- read.table(text=df, header=T)
write.table(df, "list.txt", col.names=T, row.names=F, quote=F)
It is possible to do it from R or directly in bash (both solutions could help a lot)?
First list the files in your folder
file.list <- list.files(yourfolderpath, pattern="\\.DOT$", full.names=TRUE)
Then use file.rename to rename files based on your list.txt file.
file.rename(from = file.path(dirname(file.list), list.txt$oldnam), to = file.path(dirname(file.list), list.txt$newnam))
initial files in folder
ll
total 8
-rw-r--r-- 1 root root 0 Jan 15 18:01 1.txt
-rw-r--r-- 1 root root 0 Jan 15 18:01 2.txt
-rw-r--r-- 1 root root 0 Jan 15 18:01 3.txt
-rw-r--r-- 1 root root 0 Jan 15 18:01 4.txt
-rw-r--r-- 1 root root 0 Jan 15 18:01 5.txt
-rw-r--r-- 1 root root 40 Jan 15 18:01 files
-rwxr-xr-x 1 root root 272 Jan 15 18:10 script.sh
list of files
cat files
1.txt 11.txt
2.txt 22.txt
3.txt 33.txt
running the script
./script.sh files
root#xx:~#
files in folder after running script
ll
total 8
-rw-r--r-- 1 root root 0 Jan 15 18:01 11.txt
-rw-r--r-- 1 root root 0 Jan 15 18:01 22.txt
-rw-r--r-- 1 root root 0 Jan 15 18:01 33.txt
-rw-r--r-- 1 root root 0 Jan 15 18:01 4.txt
-rw-r--r-- 1 root root 0 Jan 15 18:01 5.txt
-rw-r--r-- 1 root root 40 Jan 15 18:01 files
-rwxr-xr-x 1 root root 270 Jan 15 18:11 script.sh
the script
cat script.sh
#!/bin/bash
filename="$1"
folder_with_files=/root/
while read -r line
do
oldname=$(echo "$line" | awk '{print $1}')
newname=$(echo "$line" | awk '{print $2}')
[ -z "$oldname" ] && { break ; }
mv $folder_with_files$oldname $folder_with_files$newname
done < "$filename"

FIND_LIBRARY does not find existing libraries

In the function findQt4.cmake:
FIND_LIBRARY(QT_QTCORE_LIBRARY_RELEASE
NAMES QtCore QtCore4
HINTS ${QT_LIBRARY_DIR_TMP}
)
if I print:
MESSAGE("HINT PATH " ${QT_LIBRARY_DIR_TMP})
I will get:
~/dev/Libraries/Qt4.8.0/lib
In this directory there are: ~/dev/Libraries/Qt4.8.0/lib$ ls -all libQtCore*
I got:
-rw-r--r-- 1 abc abc 950 Nov 30 13:08 libQtCore.la
-rw-r--r-- 1 abc abc 942 Nov 30 13:07 libQtCore.prl
lrwxrwxrwx 1 abc abc 18 Nov 30 13:07 libQtCore.so -> libQtCore.so.4.8.0
lrwxrwxrwx 1 abc abc 18 Nov 30 13:08 libQtCore.so.4 -> libQtCore.so.4.8.0
lrwxrwxrwx 1 abc abc 18 Nov 30 13:08 libQtCore.so.4.8 -> libQtCore.so.4.8.0
-rwxr-xr-x 1 abc abc 2697932 Nov 30 13:08 libQtCore.so.4.8.0
But why the FIND_LIBRARY function return: QT_QTCORE_LIBRARY_RELEASE = NOT FOUND?
Even, there is no result if I do like this:
FIND_LIBRARY(QT_QTCORE_LIBRARY_RELEASE
NAMES libQtCore.so
HINTS ${QT_LIBRARY_DIR_TMP}
)
Instead of find_library() you can use find_package(). This is the common way for Qt with CMake.
# Find Qt package
find_package(Qt4 REQUIRED)
include(${QT_USE_FILE}) # Add and run Qt CMake modules
add_definitions(${QT_DEFINITIONS}) # Add definitions (if required)
# And later put all together
add_executable( ... )
target_link_libraries( ... ${QT_LIBRARIES}) # Link Qt libraries

Resources