CN110825699A - Method for rapidly counting number of disk files in C # program - Google Patents

Method for rapidly counting number of disk files in C # program Download PDF

Info

Publication number
CN110825699A
CN110825699A CN201911085033.XA CN201911085033A CN110825699A CN 110825699 A CN110825699 A CN 110825699A CN 201911085033 A CN201911085033 A CN 201911085033A CN 110825699 A CN110825699 A CN 110825699A
Authority
CN
China
Prior art keywords
file
disk
item
files
program
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201911085033.XA
Other languages
Chinese (zh)
Inventor
王小东
张玮
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Tiandihexing Technology Co Ltd
Original Assignee
Beijing Tiandihexing Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Tiandihexing Technology Co Ltd filed Critical Beijing Tiandihexing Technology Co Ltd
Priority to CN201911085033.XA priority Critical patent/CN110825699A/en
Publication of CN110825699A publication Critical patent/CN110825699A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/14Details of searching files based on file metadata
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/11File system administration, e.g. details of archiving or snapshots

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Library & Information Science (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a method for rapidly counting the number of disk files in a C # program, which comprises the following steps: s1, introducing a file searching function from the dynamic link library file through a C # program; s2, inputting a disk directory P needing to count the number of files; s3, searching a first file item in a disk directory P by using the FindFirstFile; s4, judging whether the file item is a file or a subdirectory; when the file item is a file, the file counter is incremented by 1, then the FindNextFile is used to search the next file item in the disk directory P, and the step S4 is repeated; when the file item is a subdirectory, the full path SP of the file item is taken as a parameter, and the steps S2, S3 and S4 are repeated by adopting a recursive algorithm; and S5, when the first file item in the disk directory P cannot be found or the next file item in the disk directory P cannot be found, the statistical operation is finished, and the numerical value displayed by the file counter is the number of the required disk files.

Description

Method for rapidly counting number of disk files in C # program
Technical Field
The invention relates to the field of computers, in particular to a method for rapidly counting the number of disk files in a C # program.
Background
In some tool software, a function of counting the number of disk files is often found. With the long-term use and long-term accumulation of the computer, more and more files are stored on the disk, and the time spent on counting the total number of the files on the disk is longer and longer, so that the use experience of a user on the whole software is influenced, and great obstruction is brought to the popularization and expansion work of the software.
Disclosure of Invention
The invention aims to solve the problems and provides a method for rapidly counting the number of disk files in a C # program, which improves the counting rate.
In order to achieve the purpose, the technical scheme of the invention is as follows:
a method for rapidly counting the number of disk files in a C # program comprises the following steps:
s1, introducing a file searching function from the dynamic link library file through a C # program;
s2, inputting a disk directory P needing to count the number of files;
s3, searching a first file item in a disk directory P by using the FindFirstFile;
s4, judging whether the file item is a file or a subdirectory; when the file item is a file, the file counter is incremented by 1, then the FindNextFile is used to search the next file item in the disk directory P, and the step S4 is repeated; when the file item is a subdirectory, the full path SP of the file item is taken as a parameter, and the steps S2, S3 and S4 are repeated by adopting a recursive algorithm;
and S5, when the first file item in the disk directory P cannot be found or the next file item in the disk directory P cannot be found, the statistical operation is finished, and the numerical value displayed by the file counter is the number of the required disk files.
Further, the file lookup function in step S1 is FindFirstFile, FindNextFile, and FindClose.
Compared with the prior art, the invention has the advantages and positive effects that:
the invention effectively improves the efficiency of counting the files in the disk directory, reduces the waiting time of the user for counting, improves the use effect of the counting software and makes certain contribution to the field of computer software by using the design of combining the file searching function introduced from the dynamic link library file by using the C # program and the repeated step detection of the sub-directory by using the recursive algorithm.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to these drawings without creative efforts.
FIG. 1 is a block diagram of the framework of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived from the embodiments of the present invention by a person skilled in the art without any creative effort, should be included in the protection scope of the present invention.
The invention provides a method for rapidly counting the number of disk files in a C # program, which is approximately doubled in speed compared with the method for counting the disk files by calling NET Framework 4.0 API.
FIG. 1 shows a flow chart of an implementation of the technique for rapidly counting the number of disk files; as shown in FIG. 1, the operation steps of the present invention are:
(1) windows API was introduced from kernel32.dll in C # program: FindFirstFile, FindNextFile and FindClose;
(2) inputting a disk directory P needing to count the number of files;
(3) call FindFirstFile to find the first file (i.e., file item) within directory P;
(4) if not found, the number of the files in the disk is 0; if the file is found, judging whether the file is a file or a subdirectory; if the file is a file, adding 1 to the file counter, calling the FindNextFile to search the next file (namely the file item) in the directory P, repeating the step (4) when the next file is found, and finishing the statistical operation when the next file cannot be found; and (4) if the first file in the directory P is the subdirectory S, taking the full path SP of the subdirectory S as a parameter, and carrying out isomorphic recursive algorithm from the steps (2), (3) and (4) until the statistical operation is finished.
Comparison of experiments
Compared with a statistical method of a C # program directly called NET Framework 4.0API, taking scanning of a partition C disk where an operating system is located as an example, the implementation comparison test data of the technology is shown in the following table:
Figure BDA0002265133210000031
description of the drawings:
both algorithms one and two are implemented by the same recursive algorithm as the present algorithm, see fig. 1. Each algorithm experiment was run 2 times.
Number of files: since the C disk is a system disk, the number of the temporary files or the cache files in the C disk changes, so the counted number is different, but does not affect the consideration of the execution speed of the algorithm itself.
Statistical time (ms): to count the time required for one C-disc, unit of milliseconds.
Average time (ms/f): the average time required for each file is counted in milliseconds.
Compared with the method for realizing statistics by calling the disk file of the NET Framework 4.0API, the method for realizing statistics in the disk directory has the advantages that the speed is improved by nearly one time, the efficiency of statistics of the file in the disk directory is effectively improved, the statistics waiting time of a user is reduced, the use effect of statistical software is improved, and certain contribution is made to the field of computer software.

Claims (2)

1. A method for rapidly counting the number of disk files in a C # program is characterized in that: the method comprises the following steps:
s1, introducing a file searching function from the dynamic link library file through a C # program;
s2, inputting a disk directory P needing to count the number of files;
s3, searching a first file item in a disk directory P by using the FindFirstFile;
s4, judging whether the file item is a file or a subdirectory; when the file item is a file, the file counter is incremented by 1, then the FindNextFile is used to search the next file item in the disk directory P, and the step S4 is repeated; when the file item is a subdirectory, the full path SP of the file item is taken as a parameter, and the steps S2, S3 and S4 are repeated by adopting a recursive algorithm;
and S5, when the first file item in the disk directory P cannot be found or the next file item in the disk directory P cannot be found, the statistical operation is finished, and the numerical value displayed by the file counter is the number of the required disk files.
2. The method for rapidly counting the number of disk files in a C # program according to claim 1, wherein: the file lookup functions in step S1 are FindFirstFile, FindNextFile, and FindClose.
CN201911085033.XA 2019-11-08 2019-11-08 Method for rapidly counting number of disk files in C # program Pending CN110825699A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911085033.XA CN110825699A (en) 2019-11-08 2019-11-08 Method for rapidly counting number of disk files in C # program

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911085033.XA CN110825699A (en) 2019-11-08 2019-11-08 Method for rapidly counting number of disk files in C # program

Publications (1)

Publication Number Publication Date
CN110825699A true CN110825699A (en) 2020-02-21

Family

ID=69553394

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911085033.XA Pending CN110825699A (en) 2019-11-08 2019-11-08 Method for rapidly counting number of disk files in C # program

Country Status (1)

Country Link
CN (1) CN110825699A (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5884298A (en) * 1996-03-29 1999-03-16 Cygnet Storage Solutions, Inc. Method for accessing and updating a library of optical discs
CN101727448A (en) * 2008-10-10 2010-06-09 英业达股份有限公司 Method and device for traversing directory of electronic device
CN102289451A (en) * 2011-06-17 2011-12-21 奇智软件(北京)有限公司 Method and device for searching files or folders
CN106874370A (en) * 2016-12-30 2017-06-20 厦门天锐科技股份有限公司 A kind of method for quickly retrieving of catalogue file

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5884298A (en) * 1996-03-29 1999-03-16 Cygnet Storage Solutions, Inc. Method for accessing and updating a library of optical discs
CN101727448A (en) * 2008-10-10 2010-06-09 英业达股份有限公司 Method and device for traversing directory of electronic device
CN102289451A (en) * 2011-06-17 2011-12-21 奇智软件(北京)有限公司 Method and device for searching files or folders
CN106874370A (en) * 2016-12-30 2017-06-20 厦门天锐科技股份有限公司 A kind of method for quickly retrieving of catalogue file

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
DEKEVIN: "c#调用api (FindFirstFile,FindNextFile)高效遍历目录文件", 《博客园》 *

Similar Documents

Publication Publication Date Title
US8516462B2 (en) Method and apparatus for managing a stack
US8782629B2 (en) Associating program execution sequences with performance counter events
US20110320415A1 (en) Piecemeal list prefetch
CN103220430B (en) A kind of method that mobile phone first line of a couplet people from system is searched and device
EP3832493B1 (en) Method, apparatus, electronic device and readable storage medium for data query
CN101651576A (en) Alarm information processing method and system
US20160274991A1 (en) Optimization of Hardware Monitoring for Computing Devices
US11405413B2 (en) Anomaly lookup for cyber security hunting
US10509641B2 (en) Optimizing feature deployment based on usage pattern
CN106951550A (en) Data processing method, device and mobile terminal
CN107357794B (en) Method and device for optimizing data storage structure of key value database
Li et al. BP-growth: Searching strategies for efficient behavior pattern mining
US8549309B1 (en) Asymmetric content fingerprinting with adaptive window sizing
EP4010828A1 (en) Automatic generation of detection alerts
CN110032418A (en) A kind of screenshot method, system, terminal device and computer readable storage medium
CN106227413A (en) A kind of application based on mobile terminal starts detection method and system
US10372299B2 (en) Preserve input focus in virtualized dataset
CN110825699A (en) Method for rapidly counting number of disk files in C # program
CN113411224B (en) Data processing method and device, electronic equipment and storage medium
CN107734610A (en) Message treatment method, mobile terminal and computer-readable recording medium
CN108632366B (en) File downloading method and device and terminal equipment
CN105979021A (en) Information processing method and user terminal
CN113342270A (en) Volume unloading method and device and electronic equipment
CN108604192B (en) System, method, and medium for performing one or more tasks while waiting for an event to be recorded
WO2024066376A1 (en) Data storage method and apparatus, electronic device, and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20200221