Mehrere Textfiles kopieren mit file_copy

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Mehrere Textfiles kopieren mit file_copy

    Hallo Experten!

    Mache wieder einmal eine kleine Anwendung mit vielen Textfiles, welche sich in einem Ordner auf C:/ befinden und finde keine Möglichkeit, diese auf einfache Weise von C:/... in den Anwendungsordner zu kopieren.
    Derzeit mache ich es sehr aufwendig sozusagen zu Fuß mit:

    GML-Quellcode

    1. if file_exists('C:\Save\TextA1.txt') file_copy('C:\Save\TextA1.txt','TextA1.txt')

    .....

    GML-Quellcode

    1. if file_exists('C:\Save\TextB29.txt') file_copy('C:\Save\TextB29.txt','TextB29.txt')


    Habe erfolglos versucht mit:

    GML-Quellcode

    1. if file_exists('C:\Save\Text*.txt') file_copy('C:\Save\Text*.txt','Text*.txt')

    GML-Quellcode

    1. if file_exists('C:\Save\Text' + '*.txt') file_copy('C:\Save\Text' + '*.txt','Text' + '*.txt')

    GML-Quellcode

    1. if file_exists('C:\Save\Text' + '*' + '.txt') file_copy('C:\Save\Text' + '*' + '.txt','Text' + '*' + '.txt')


    Zum Löschen von Files verwende ich folgenden Code, welcher einwandfrei funktioniert:

    GML-Quellcode

    1. file=file_find_first('Text*.txt',noone)
    2. while !(file="")
    3. {
    4. file_delete(''+file)
    5. file=file_find_next()
    6. }

    Gibt es eine Möglichkeit, alle diese Textfiles zu übertragen, ohne jedes einzele File anführen zu müssen?

    Würde mich über eine Hilfreiche Antwort sehr freuen
    Mit freundlichen Grüßen
    Hubsl
  • Danke für die Info, habe ich schon probiert, kenn mich aber mit file_find_first usw. nicht wirklich aus.
    Hier mein Code, welcher nicht richtig funktioniert:

    GML-Quellcode

    1. file=file_find_first('C:\SaveMo2plus\mo2name*.txt',noone)
    2. while !(file="")
    3. {
    4. file_copy('C:\SaveMo2plus\mo2name*.txt',''+file)
    5. file=file_find_next()
    6. }


    Wäre super, wenn du mir diesen Code richtigstellen könntest.
    Ich bedanke mich schon im Voraus dafür.

    MfG. Hubsl
  • Bedenke dass GM Studios File-zugriffe Sandboxed sind.
    Sprich: Du kannst nur Dateien lesen welche in der Game-directory liegen ("included files") oder in der working-directly (appdata) lesen/schreiben.

    Einen direkten pfad (wie in dem Fall unter "C:/...") anzugeben wird nicht funktionieren da dieser außerhalb der Sandbox liegt.
  • Ist mir schon klar, aber mit dem Studio 2 IDE v2.2.4.474, Laufzeit v2.2.4.374 kann unter Optionen/Windows/ Dateisystem-Sandbox deaktivieren angekreuzt werden.
    Außerdem gibt es die Erweiterung WinDev.

    Mein Projekt sieht folgendermaßen aus:
    Damit ich ein Spiel, welches mit GMS2 erstellt wurde auf einem STIC verwenden kann, bei welchem auch Textfiles auf dem STIC gespeichert werden können, verwende ich zusätzlich eine kleine GM81.exe.
    1.Spiel Start am STIC --> GM81.exe wird gestartet, überträgt alle Textfiles in einen Ordner nach C:/ und startet das GMS2-Spiel
    2.Am Beginn des GMS2-Spiels werden diese Textfiles von C:/... in die working_directory übertragen.
    3.Spieldaten werden während des Spiels in Textfiles gespeichert und nach C:/... kopiert.
    4.GM81.exe kopiert diese Textfiles wieder auf den STIC.
    5.Bei Spiel-Ende wird ein Textfile "ende.txt" mit dem Inhalt "0" erzeugt und auf C:/... gespeichert.
    6.GMS81.exe wird bei "ende=0" geschlossen.

    Ich habe leider keine einfachere Methode gefunden, Daten auf dem STIC zu speichern und auch wieder vom STIC zu laden. Es ist ja bei jedem PC oder Laptop, auf welchem dieser STIC zum Einsatz kommt, ein anderer Laufwerkbuchstabe zu erwarten.

    MfG. Hubsl
  • Probier mal statt "file_copy('C:\SaveMo2plus\mo2name*.txt',''+file)" -> "file_copy(file,filename_name(file))"

    Weiß jetzt nicht, ob die filename_name() funktion auch die dateiendung mit ausspuckt, ansonsten noch mit dranhängen.
  • Komm einfach nicht damit (file_find_first usw.) zurecht. ;(

    So funktioniert es derzeit auf die komplizierte Methode

    GML-Quellcode

    1. if file_exists("C:\SaveMo2plus\mo2name1.txt") file_copy("C:\SaveMo2plus\mo2name1.txt","docs\mo2name1.txt")
    2. if file_exists("C:\SaveMo2plus\mo2name1moue1a01.txt") file_copy("C:\SaveMo2plus\mo2name1moue1a01.txt","docs\mo2name1moue1a01.txt")
    3. if file_exists("C:\SaveMo2plus\mo2name1moue1a02.txt") file_copy("C:\SaveMo2plus\mo2name1moue1a02.txt","docs\mo2name1moue1a02.txt")
    4. if file_exists("C:\SaveMo2plus\mo2name1moue1a03.txt") file_copy("C:\SaveMo2plus\mo2name1moue1a03.txt","docs\mo2name1moue1a03.txt")
    5. if file_exists("C:\SaveMo2plus\mo2name1moue1a04.txt") file_copy("C:\SaveMo2plus\mo2name1moue1a04.txt","docs\mo2name1moue1a04.txt")
    6. if file_exists("C:\SaveMo2plus\mo2name1moue1a05.txt") file_copy("C:\SaveMo2plus\mo2name1moue1a05.txt","docs\mo2name1moue1a05.txt")
    7. if file_exists("C:\SaveMo2plus\mo2name1moue1a06.txt") file_copy("C:\SaveMo2plus\mo2name1moue1a06.txt","docs\mo2name1moue1a06.txt")
    8. if file_exists("C:\SaveMo2plus\mo2name1moue1a07.txt") file_copy("C:\SaveMo2plus\mo2name1moue1a07.txt","docs\mo2name1moue1a07.txt")
    9. if file_exists("C:\SaveMo2plus\mo2name1moue1a08.txt") file_copy("C:\SaveMo2plus\mo2name1moue1a08.txt","docs\mo2name1moue1a08.txt")
    10. if file_exists("C:\SaveMo2plus\mo2name1moue1a09.txt") file_copy("C:\SaveMo2plus\mo2name1moue1a09.txt","docs\mo2name1moue1a09.txt")
    11. if file_exists("C:\SaveMo2plus\mo2name1moue1a10.txt") file_copy("C:\SaveMo2plus\mo2name1moue1a10.txt","docs\mo2name1moue1a10.txt")
    12. if file_exists("C:\SaveMo2plus\mo2name1moue1a11.txt") file_copy("C:\SaveMo2plus\mo2name1moue1a11.txt","docs\mo2name1moue1a11.txt")
    13. if file_exists("C:\SaveMo2plus\mo2name1moue1a12.txt") file_copy("C:\SaveMo2plus\mo2name1moue1a12.txt","docs\mo2name1moue1a12.txt")
    Alles anzeigen


    Leider habe ich mehrere Hundert Dateien und diese alle aufzulisten ist halt sehr aufwendig.
    Vielleicht gibt es doch eine einfachere Lösung, würde mir sehr helfen.
    Noch ein Detail:
    Mit folgendem Code werden nur die Textfiles im Ordner direkt gelöscht, nicht aber im angegebenen Zielordner!

    GML-Quellcode

    1. file=file_find_first("C:\SaveMo2plus\mo2name*.txt",noone)while !(file=""){ file_delete(""+file) file=file_find_next()}file_find_close()

    Dieser Beitrag wurde bereits 3 mal editiert, zuletzt von hubsl () aus folgendem Grund: Korrektur Rechtschreibfehler

  • Benutzer online 1

    1 Besucher