Kopieren,Einfügen,Umbennen



  • thomas89 schrieb:

    PS:CopyFile verhält sich genauso wie MoveFile?

    nein copy == kopieren und move == verschieben 😉 wie der name schon sagt



  • Problemo!
    wenn ich CopyFile("blablabla","lalala")kommt funktion does not support two parameters
    Muss da noch ne Einfügen Version ran?



  • der 3. parameter ist ein Flag ob die Datei falls vorhanden überschrieben werden soll:

    MSDN schrieb:

    The CopyFile function copies an existing file to a new file.

    BOOL CopyFile(
    LPCTSTR lpExistingFileName,
    // pointer to name of an existing file
    LPCTSTR lpNewFileName, // pointer to filename to copy to
    BOOL bFailIfExists // flag for operation if file exists
    );

    Parameters
    lpExistingFileName
    Pointer to a null-terminated string that specifies the name of an existing file.
    lpNewFileName
    Pointer to a null-terminated string that specifies the name of the new file.
    bFailIfExists
    Specifies how this operation is to proceed if a file of the same name as that specified by lpNewFileName already exists. If this parameter is TRUE and the new file already exists, the function fails. If this parameter is FALSE and the new file already exists, the function overwrites the existing file and succeeds.



  • Danke,aber jetzt raff ich immer noch nicht durch.
    1.Warum BOOL
    2.Muss der pointer nich erst mal initialisiert werden?
    3.Wie kriegt man nun den Quellpfad rein?
    is IpExisting FileNamee nur nen Synonym für C:\und so weiter oder is es nen string?



  • Ich denke du solltest dir erstmal ein C/C++-Buch anschauen 🙄

    BOOL ist der Rückgabetyp - damit meldet die Funktion, ob der Vorgang geklappt hat, oder nicht
    LPCTSTR ist ein Pointer zu einer Zeichenkette

    z.B. so:

    if(!CopyFile("e:\\dir1\\anwendung.exe","d:\\da\\soll\\sie\\hin\\anwendung.exe",TRUE))
    {
      // es gab einen Fehler beim kopieren!!
    }
    


  • ja ich wusste auch was BOOL ist habs bloß nicht gecheckt! 🙄
    Aber so was wie deine Beschreibung hat mir gefehlt!Musste über mich selbst lachen!! 😃

    Ich hab das Buch Jetzt lerne ich C++ fast gelesen ,was empfiehlste mir weiter (oder auch die anderen ?)



  • Ich kriegdie Krise !
    Klappt nicht!
    Kuckt euch das ma an:

    #include <iostream.h>
    #include <windows.h>

    BOOL CopyFile(LPCTSTR IpExistingFileName,LPCTSTR IpNewFileName,BOOL bFailIfExists);

    int main()
    {
    BOOL CopyFile("F:\\lalala.ocd","C:\\Programme\\hallo.ocd");
    {
    cout<<"In Funktion CopyFile";
    }
    return 0;
    }



  • Lass mal die Funktionsdeklaration weg und schau dir mein Beispiel nochmal an - CopyFile hat 3 Parameter und die ersten beiden hast du vertauscht.

    Als Buch solltest du dir (wenn ich das hier sehe) erstmal noch ein (paar) C/C++-Bücher durcharbeiten bevor du mit WinAPI anfängst 😉



  • Vielen Dank für deine Ratschläge.
    Aber der Programmier_Novize hat noch n Problem:
    Ich hab das am Anfang weggelassen,hab die beiden vertauscht(C:an erster und F: an zweiter Stelle)und hab dann TRUE hinten dran geschrieben.Dann kam too many initializers.
    Soll ichs aufgeben?



  • Einfach nur

    CopyFile("C:\\Programme\\hallo.ocd","F:\\lalala.ocd",TRUE);
    

Anmelden zum Antworten