Question Regarding Archive Bits on Switch

  • Thread starter Thread starter littlesmurf
  • Start date Start date
  • Views Views 2,364
  • Replies Replies 21
AI coding tools are a terrible idea for things you don't understand, because it'll make horrible mistakes that you wouldn't know to correct.
Yep sometimes they can be a pain, but it's still a handy tool to have, you can get it the read part of a program and see if it will come up with things you never thought of, then you can make part of a program with one AI such as ChatGPT then feed that into DeepSeek and see if it finds any issues. Then you can always have a look yourself if it's not working. It can save you hours/days of work if you just want to make something to do a one off specific job and don't plan on sharing it.
Post automatically merged:

Yeah, I don't think it does. The archive bit is not the read only bit. It's the "I am not yet archived by an archive tool written in the 90s" bit. Trusting an AI with a codebase that maybe 100 people know well is just not a good idea.
Here;s the updated code to fix the missing archive bit:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
#include <switch.h>

#define SDMC_PATH "/switch" // Directory to scan

void set_archive_bit(const char* path) {
    struct stat file_stat;
    if (stat(path, &file_stat) == 0) {
        if (!(file_stat.st_mode & S_IFDIR)) { // Ensure it's a file, not a directory
            FILE* f = fopen(path, "r+");
            if (f) {
                fclose(f); // Just opening and closing may trigger an update
                printf("Set archive bit: %s\n", path);
            }
            else {
                printf("Failed to open: %s\n", path);
            }
        }
    }
}

void scan_directory(const char* directory) {
    DIR* dir = opendir(directory);
    if (!dir) return;

    struct dirent* entry;
    while ((entry = readdir(dir)) != NULL) {
        if (entry->d_name[0] == '.') continue; // Skip hidden files and . / ..

        char full_path[PATH_MAX];
        snprintf(full_path, sizeof(full_path), "%s/%s", directory, entry->d_name);

        struct stat path_stat;
        if (stat(full_path, &path_stat) == 0) {
            if (S_ISDIR(path_stat.st_mode)) {
                scan_directory(full_path); // Recurse into directories
            }
            else {
                set_archive_bit(full_path); // Set archive bit on files
            }
        }
    }
    closedir(dir);
}

int main(int argc, char* argv[]) {
    consoleInit(NULL);
    padConfigureInput(1, HidNpadStyleSet_NpadStandard);
    PadState pad;
    padInitializeDefault(&pad);

    printf("Scanning SD card for files to fix...\n");
    scan_directory(SDMC_PATH);
    printf("Scan complete. Press A to exit.\n");

    while (appletMainLoop()) {
        padUpdate(&pad);
        u64 kDown = padGetButtonsDown(&pad);
        if (kDown & HidNpadButton_A) break;
        consoleUpdate(NULL);
    }

    consoleExit(NULL);
    return 0;
}

Here's the Nintendo Switch homebrew program that scans the microSD card (under /switch) and sets the archive bit on all files. It opens and closes each file, which can trigger an update to the file attributes.

How It Works:

  • Recursively scans the /switch directory.
  • Opens each file to try and trigger the archive bit.
  • Skips directories and hidden files.
  • Shows progress on-screen.
  • Press + to exit.
 
Last edited by littlesmurf,
  • Haha
Reactions: JK_

Site & Scene News

Popular threads in this forum