datei adtribute
-
hi,
wie kann man von einer datei die adtribute änder um die datei zb zu ändern?
-
Benutz die Forumsuche, das hatten wir letztens!
-
hab ich gelsen aber ich cheack das irgetwie nich !! kann jemand mir liebeswürdiger weise ein bespiel code hier posten wo zb datei C:/z.txt zb auf schreibgestüzt gesetzt wird??
-
Sozusagen, jo:
An application can retrieve the file attributes by using the GetFileAttributes or GetFileAttributesEx function. The CreateFile and SetFileAttributes functions can set many of the attributes. However, applications cannot set all attributes.
The code example in this topic uses the CopyFile function to copy all text files (.txt) in the current directory to a new directory of read-only files named \TextRO. Files in the new directory are changed to read only, if necessary.
The application creates the \TextRO directory by using the CreateDirectory function.
The application searches the current directory for all text files by using the FindFirstFile and FindNextFile functions. Each text file is copied to the \TextRO directory. After a file is copied, the GetFileAttributes function determines whether or not a file is read only. If the file is not read only, the application changes directories to \TextRO and converts the copied file to read only by using the SetFileAttributes function.
After all text files in the current directory are copied, the application closes the search handle by using the FindClose function.
#include <windows.h> #include <stdio.h> void main() { WIN32_FIND_DATA FileData; HANDLE hSearch; DWORD dwAttrs; TCHAR szDirPath[] = TEXT("c:\\TextRO\\"); TCHAR szNewPath[MAX_PATH]; BOOL fFinished = FALSE; // Create a new directory. if (!CreateDirectory(szDirPath, NULL)) { printf("Could not create new directory.\n"); return; } // Start searching for text files in the current directory. hSearch = FindFirstFile(TEXT("*.txt"), &FileData); if (hSearch == INVALID_HANDLE_VALUE) { printf("No text files found.\n"); return; } // Copy each .TXT file to the new directory // and change it to read only, if not already. while (!fFinished) { lstrcpy(szNewPath, szDirPath); lstrcat(szNewPath, FileData.cFileName); if (CopyFile(FileData.cFileName, szNewPath, FALSE)) { dwAttrs = GetFileAttributes(FileData.cFileName); if (dwAttrs==INVALID_FILE_ATTRIBUTES) return; if (!(dwAttrs & FILE_ATTRIBUTE_READONLY)) { SetFileAttributes(szNewPath, dwAttrs | FILE_ATTRIBUTE_READONLY); } } else { printf("Could not copy file.\n"); return; } if (!FindNextFile(hSearch, &FileData)) { if (GetLastError() == ERROR_NO_MORE_FILES) { printf("Copied all text files.\n"); fFinished = TRUE; } else { printf("Could not find next file.\n"); return; } } } // Close the search handle. FindClose(hSearch); }
-
fatal error C1083: Datei (Include) kann nicht geöffnet werden: "windows.h": No such file or directory was soll ich machen?
-
Was für eine IDE??? VC 2005 Express? Dann musst Du noch das PSDK installieren:
http://www.c-plusplus.net/forum/viewtopic-var-t-is-143003.html
-
error C2664: 'SetFileAttributesW': Konvertierung des Parameters 1 von 'const char [12]' in 'LPCWSTR' nicht möglich Die Typen, auf die verwiesen wird, sind nicht verknüpft; die Konvertierung erfordert einen reinterpret_cast-Operator oder eine Typumwandlung im C- oder Funktionsformat.sag der jetz immer !!! was mach ich falsch?
hier der code:
#include <windows.h>
int main()
{
SetFileAttributes("c:\\test.txt",FILE_ATTRIBUTE_SYSTEM);
return 0;
}[/code]
-
Oh...das sind Grundlagen...der meckert wg. UNICODE...so müsste es gehen:
#include <Windows.h> int main() { SetFileAttributes(TEXT("C:\\test.txt"), FILE_ATTRIBUTE_SYSTEM); return (0) }EDIT: Denn: VC2005 Express Ed. kompiliert nach Voreinstellung autom. auf UNICODE.