2929void dir (String path) {
3030 std::vector<String> directories;
3131 collectDirectories (path, directories);
32- for (auto directory: directories) {
32+ for (auto directory : directories) {
3333 printDirectoryName (directory.c_str (), 1 );
3434 File fs = SD.open (directory);
3535 printFilesInDirectory (fs);
@@ -75,30 +75,30 @@ void printDirectoryName(const char* name, uint8_t level) {
7575
7676// helper function: combine path
7777String joinPath (const String &base, const String &name) {
78- if (base.endsWith (" /" )) {
79- return base + name;
80- }
81- return base + " /" + name;
78+ if (base.endsWith (" /" )) {
79+ return base + name;
80+ }
81+ return base + " /" + name;
8282}
8383
8484// recusive function to collect directory names
8585void collectDirectories (const String &dirname, std::vector<String> &directories) {
86- File root = SD.open (dirname);
87- if (!root || !root.isDirectory ()) {
88- Serial.printf (" Error: Verzeichnis %s konnte nicht geöffnet werden\n " , dirname.c_str ());
89- return ;
90- }
91- directories.push_back (dirname); // Verzeichnis speichern
92-
93- File file = root.openNextFile ();
94- while (file) {
95- if (file.isDirectory ()) {
96- String fullPath = joinPath (dirname, file.name ()); // Vollständigen Pfad erstellen
97- collectDirectories (fullPath, directories); // Rekursiver Aufruf
98- }
99- file = root.openNextFile ();
100- }
101- root.close ();
86+ File root = SD.open (dirname);
87+ if (!root || !root.isDirectory ()) {
88+ Serial.printf (" Error: Verzeichnis %s konnte nicht geöffnet werden\n " , dirname.c_str ());
89+ return ;
90+ }
91+ directories.push_back (dirname); // Verzeichnis speichern
92+
93+ File file = root.openNextFile ();
94+ while (file) {
95+ if (file.isDirectory ()) {
96+ String fullPath = joinPath (dirname, file.name ()); // Vollständigen Pfad erstellen
97+ collectDirectories (fullPath, directories); // Rekursiver Aufruf
98+ }
99+ file = root.openNextFile ();
100+ }
101+ root.close ();
102102}
103103
104104// print filenames
@@ -110,7 +110,7 @@ void printFileName(File file) {
110110 Serial.print (file.size (), DEC);
111111 time_t cr = file.getCreationTime ();
112112 time_t lw = file.getLastWrite ();
113- struct tm * tmstruct = localtime (&cr);
113+ struct tm * tmstruct = localtime (&cr);
114114 Serial.printf (" \t CREATION: %d-%02d-%02d %02d:%02d:%02d" , (tmstruct->tm_year ) + 1900 , (tmstruct->tm_mon ) + 1 , tmstruct->tm_mday , tmstruct->tm_hour , tmstruct->tm_min , tmstruct->tm_sec );
115115 tmstruct = localtime (&lw);
116116 Serial.printf (" \t LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n " , (tmstruct->tm_year ) + 1900 , (tmstruct->tm_mon ) + 1 , tmstruct->tm_mday , tmstruct->tm_hour , tmstruct->tm_min , tmstruct->tm_sec );
@@ -127,8 +127,7 @@ void printFilesInDirectory(File dir) {
127127 }
128128 if (file.isDirectory ()) {
129129 continue ;
130- }
131- else {
130+ } else {
132131 printFileName (file);
133132 }
134133 }
0 commit comments