📄 chgattr.c
字号:
#include<windows.h>
#include<stdio.h>
int main()
{
WIN32_FIND_DATA FileData;
HANDLE hSearch;
DWORD dwAttrs;
char szDirPath[] = "c:\\TEXTRO\\";
char szNewPath[MAX_PATH];
BOOL fFinished = FALSE;
// Create a new directory.
if (!CreateDirectory(szDirPath, NULL))
{
printf("%s","Couldn't create new directory.");
}
// Start searching for .TXT files in the current directory.
hSearch = FindFirstFile("*.txt", &FileData);
if (hSearch == INVALID_HANDLE_VALUE)
{
printf("%s","No .TXT files found.");
return 0;
}
// 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 & FILE_ATTRIBUTE_READONLY))
{
SetFileAttributes(szNewPath,
dwAttrs | FILE_ATTRIBUTE_READONLY);
}
}
else
{
printf("%s","Couldn't copy file.");
}
if (!FindNextFile(hSearch, &FileData))
{
if (GetLastError() == ERROR_NO_MORE_FILES)
{
MessageBox(NULL, "No more .TXT files.",
"Search completed.", MB_OK);
fFinished = TRUE;
}
else
{
printf("%s","Couldn't find next file.");
return 0;
}
}
}
// Close the search handle.
if (!FindClose(hSearch))
{
printf("%s","Couldn't close search handle.");
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -