Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Центр помощи > [Delphi] Создание временного файла


Автор: Diesel Draft 15.12.2006, 02:42
Я в розпаче, отщущаю себя полным нубом в делфи  smile . Спасите мою бедною душу и подкстажите как создать темповкый файл.  smile 

Автор: Nicholas_S 15.12.2006, 02:49
сначала убрать темповые руки, темповые глаза (чтобы видеть замечания) и темповые формулировки вопросов.  smile 

Автор: Matematik 15.12.2006, 08:51
GetTempFileName()
Код

#include <windows.h>
#include <stdio.h>

#define BUFSIZE 4096

int main()
{
    HANDLE hFile;
    HANDLE hTempFile; 
    DWORD  dwBytesRead, dwBytesWritten, dwBufSize=BUFSIZE;
    char szTempName[MAX_PATH];
    char buffer[BUFSIZE]; 
    char lpPathBuffer[BUFSIZE];
 
    // Open the existing file. 
 
    hFile = CreateFile("original.txt",  // file name 
        GENERIC_READ,                   // open for reading 
        0,                              // do not share 
        NULL,                           // default security 
        OPEN_EXISTING,                  // existing file only 
        FILE_ATTRIBUTE_NORMAL,          // normal file 
        NULL);                          // no template 
    if (hFile == INVALID_HANDLE_VALUE) 
    { 
        printf("Could not open file.");
        return 0;
    } 
 
    // Get the temp path

    GetTempPath(dwBufSize,   // length of the buffer
         lpPathBuffer);      // buffer for path 

    // Create a temporary file. 
    
    GetTempFileName(lpPathBuffer, // directory for temp files 
        "NEW",                    // temp file name prefix 
        0,                        // create unique name 
        szTempName);              // buffer for name 

    hTempFile = CreateFile((LPTSTR) szTempName,  // file name 
        GENERIC_READ | GENERIC_WRITE, // open for read/write 
        0,                            // do not share 
        NULL,                         // default security 
        CREATE_ALWAYS,                // overwrite existing file
        FILE_ATTRIBUTE_NORMAL,        // normal file 
        NULL);                        // no template 

    if (hTempFile == INVALID_HANDLE_VALUE) 
    { 
        printf("Could not create temporary file."); 
        return 0;
    } 
 
    // Read 4K blocks to the buffer. 
    // Change all characters in the buffer to upper case. 
    // Write the buffer to the temporary file. 
 
    do 
    {
        if (ReadFile(hFile, buffer, 4096, 
            &dwBytesRead, NULL)) 
        { 
            CharUpperBuff(buffer, dwBytesRead); 
  
            WriteFile(hTempFile, buffer, dwBytesRead, 
                &dwBytesWritten, NULL); 
        } 
    } while (dwBytesRead == BUFSIZE); 
 
    // Close both files. 
 
    CloseHandle(hFile); 
    CloseHandle(hTempFile); 
 
    // Move the temporary file to the new text file.
 
    if (!MoveFileEx(szTempName, 
                    "allcaps.txt", 
                    MOVEFILE_REPLACE_EXISTING)) 
    { 
        printf("Could not move temp file.");
        return 0;
    }
}


© psdk

Автор: Romkin 15.12.2006, 13:40
Можно добавить в атрибуты FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_TEMPORARY для временного файла...

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)