Skip to content
Snippets Groups Projects
Verified Commit ad5eaf24 authored by Rafael László's avatar Rafael László :speech_balloon:
Browse files

Add project files

parents
Branches
Tags 1st
No related merge requests found
### 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
cmake_minimum_required(VERSION 3.20)
project(homework1 C)
set(CMAKE_C_STANDARD 11)
add_executable(homework1
main.c)
main.c 0 → 100644
#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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment