The process is like this! Add A record to Table A of the database. ** in the system, there will be 5 N more files under directory B. As the system has been running for more than three years, the number of files in directory B has reached more than 2 MB, and these files are frequently accessed by users. As a result, the problem arises: on the one hand, the speed of file access by users is slow; on the other hand, there are too many files and it is difficult to maintain them.
What should we do? After A long time, we found that there is A time field in Table A that won't be changed. If you intercept the year + month of the input time to create the sub-directory name under the B directory and archive the new files in the current month under the sub-directory, isn't that all right? After the newly added files are processed, you can pay a weekly discount on the archiving of old files because the files have to be migrated to the new subdirectories.
The following is the main code for file migration:
- Static void Main (string [] args)
- {
- String paperPath = ConfigurationManager. receivettings ["PaperBuildPath"];
- Console. WriteLine (string. Format ("Exam Directory: {0}", paperPath ));
- Console. WriteLine ();
- Console. WriteLine ("is the directory correct? Press any key ......");
- Console. WriteLine ();
- Console. ReadKey ();
- String [] files = Directory. GetFiles (paperPath );
- Int num = 0;
- PublicExam [] list = Gateway. Default. FindArray <PublicExam> ();
- Foreach (PublicExam publicExam in list)
- {
- Foreach (string file in files)
- {
- // Source file name (after path removal)
- String fileName = file. Split ('\'). Last ();
- If (fileName. StartsWith (publicExam. FGuid. ToString (), StringComparison. CurrentCultureIgnoreCase ))
- {
- // Target folder
- String destFilePath = paperPath + publicExam. FInputTime. ToString ("yyyyMM ");
- If (Directory. Exists (destFilePath) = false)
- Directory. CreateDirectory (destFilePath );
- // Target file name
- String destFileName = destFilePath + "\" + fileName;
- If (File. Exists (destFileName ))
- File. Delete (destFileName );
- Console. WriteLine (string. Format ("migrating file: {0}", fileName ));
- // Migrate the file
- File. Move (file, destFileName );
- Num ++;
- }
- }
- }
- Console. WriteLine ();
- Console. WriteLine (string. Format ("A total of {0} files are migrated. Press any key to exit...", num ));
- Console. ReadKey ();
- }
The above example references how to use the File Class and Directory Class in MSDN.
Run the following command:
Tips:
Directory Name (Year + month) for example: 201101
C # => DateTime. Now. ToString ("yyyyMM ")
SQL => convert (varchar (6), getdate (), 112)
Of course, file migration alone is not enough. There is still a lot of work to be done, such as modifying programs and updating database table records. I know that this "operation" does not comply with the open-close principle.
Measure the test taker's knowledge about the Oracle file system mechanism.
Explain how MongoDB accelerates the storage of physical files and SQUID
Description of the DB2 external file format
Analysis of DB2 external file format
Oracle Database File Management Experience