Read content of directory file [duplicate] - c

This question already has answers here:
Using `read` system call on a directory
(2 answers)
Linux C read a directory
(2 answers)
Closed 3 years ago.
It's possible to read a regular file or a symbolic link file ( not the file it's pointing to ).
Is there a way to read the content of a directory file in a file reading fashion (e.g. fread()) .

Related

Iterate a bash array with spaces in the strings? [duplicate]

This question already has answers here:
When to wrap quotes around a shell variable?
(5 answers)
Bash arbitrary glob pattern (with spaces) in for loop
(2 answers)
Closed 2 years ago.
I'm trying to read a bash array file by file but for files with spaces in them, it comes out as two separate files. How would I solve this?
file names:
file A
fileB
file_C
the output Im getting is like this
File
A
FileB
File_C
What Im trying to do is to get File A on one line
I know I can read the array at once but for now we need to do it with a for loop since we're gonna be doing operations to it later in the loop.
for i in "${array[#]}"; do
echo "$i"
done

Mmaping shell-opened stdout [duplicate]

This question already has answers here:
Change read/write permissions on a file descriptor
(2 answers)
Reopen a file descriptor with another access?
(2 answers)
Closed 3 years ago.
Shells open redirected stdout with O_WRONLY. Such files cannot be mmaped (Write-only mapping a O_WRONLY opened file supposed to work?). Is there a work-around for this? Can I reopen the same filedescriptor (i.e., 1 == STDOUT_FILENO) but with O_RDWR without knowing a/the name of the file?

How to edit stringd in a batch file [duplicate]

This question already has answers here:
Batch string replace
(3 answers)
Closed 6 years ago.
i'm new to batch programming but i cant find how to manipulate string in a specific manner like we would do in C++.
i want to create a batch file which would change.
00:1E:90:75:9F:9F
to
001E90759F9F
maybe you can try this:
sed 's/00:1E:90:75:9F:9F/001E90759F9F/' your_file_name

Can you Hide files in c? [duplicate]

This question already has answers here:
Hide a file or directory using the Windows API from C
(4 answers)
Closed 8 years ago.
Does anybody know if it is possible to hide files or make them invisible to other users? Or, does creating file in "w" mode achieve invisibility?
Ex:
If I create a file like this:
FILE *fp = fopen("aFile","w");
Can other users on my system read it?
I guess I'm asking for the C way to add access modifiers to files in C, sort of like the chmod command does..
It is not possible to set access permission when using fopen.
Use CreateFile instead to open file and set access permissions.

How to make a bash shell script execute in C? [duplicate]

This question already has answers here:
How do I execute a command and get the output of the command within C++ using POSIX?
(12 answers)
How to run a bash script from C++ program
(5 answers)
Closed 8 years ago.
How might I go about writing a program in C that executes a .sh (shell script) file? I'm writing a program, and one of the functions requires running some shell scripts. Thanks!
Use the system function
system("myscript.sh");

Resources