Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
Linux Homeworks
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Rafael László
Linux Homeworks
Commits
ad5eaf24
Verified
Commit
ad5eaf24
authored
Oct 12, 2021
by
Rafael László
Browse files
Options
Downloads
Patches
Plain Diff
Add project files
parents
Branches
Branches containing commit
Tags
1st
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+79
-0
79 additions, 0 deletions
.gitignore
CMakeLists.txt
+7
-0
7 additions, 0 deletions
CMakeLists.txt
main.c
+66
-0
66 additions, 0 deletions
main.c
with
152 additions
and
0 deletions
.gitignore
0 → 100644
+
79
−
0
View file @
ad5eaf24
### C++ template
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/workspace.xml
.idea/tasks.xml
.idea/dictionaries
.idea/vcs.xml
.idea/jsLibraryMappings.xml
# Sensitive or high-churn files:
.idea/dataSources.ids
.idea/dataSources.xml
.idea/dataSources.local.xml
.idea/sqlDataSources.xml
.idea/dynamic.xml
.idea/uiDesigner.xml
# Gradle:
.idea/gradle.xml
.idea/libraries
# Mongo Explorer plugin:
.idea/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
.idea
cmake-build-debug
\ No newline at end of file
This diff is collapsed.
Click to expand it.
CMakeLists.txt
0 → 100644
+
7
−
0
View file @
ad5eaf24
cmake_minimum_required
(
VERSION 3.20
)
project
(
homework1 C
)
set
(
CMAKE_C_STANDARD 11
)
add_executable
(
homework1
main.c
)
This diff is collapsed.
Click to expand it.
main.c
0 → 100644
+
66
−
0
View file @
ad5eaf24
#include
<stdio.h>
#include
<unistd.h>
#include
<dirent.h>
#include
<string.h>
#include
<malloc.h>
int
count_files_in_dir
(
char
*
path
)
{
int
file_count
=
0
;
DIR
*
dir
;
struct
dirent
*
entry
;
dir
=
opendir
(
path
);
while
((
entry
=
readdir
(
dir
))
!=
NULL
)
{
if
(
strcmp
(
entry
->
d_name
,
"."
)
==
0
||
strcmp
(
entry
->
d_name
,
".."
)
==
0
)
{
continue
;
}
file_count
++
;
}
closedir
(
dir
);
return
file_count
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
==
1
)
{
printf
(
"Not enough parameters provided!"
);
return
1
;
}
else
{
DIR
*
dir
;
struct
dirent
*
entry
;
dir
=
opendir
(
argv
[
1
]);
if
(
!
dir
)
{
return
0
;
}
while
((
entry
=
readdir
(
dir
))
!=
NULL
)
{
if
(
strcmp
(
entry
->
d_name
,
"."
)
==
0
||
strcmp
(
entry
->
d_name
,
".."
)
==
0
)
{
continue
;
}
char
*
entry_path
;
// string concatenation
if
((
entry_path
=
malloc
(
strlen
(
argv
[
1
])
+
strlen
(
entry
->
d_name
)
+
2
))
!=
NULL
){
entry_path
[
0
]
=
'\0'
;
strcat
(
entry_path
,
argv
[
1
]);
strcat
(
entry_path
,
"/"
);
strcat
(
entry_path
,
entry
->
d_name
);
}
else
{
return
1
;
}
if
(
entry
->
d_type
==
DT_REG
)
{
unlink
(
entry_path
);
}
else
if
(
entry
->
d_type
==
DT_DIR
&&
count_files_in_dir
(
entry_path
)
==
0
)
{
rmdir
(
entry_path
);
}
free
(
entry_path
);
}
closedir
(
dir
);
if
(
count_files_in_dir
(
argv
[
1
])
==
0
)
{
rmdir
(
argv
[
1
]);
}
else
{
printf
(
"Couldn't delete all files, because there was a non empty folder!
\n
"
);
return
1
;
}
return
0
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment