


How to quickly generate the text path of data? C++ implements text path generation
文本路径读取
在机器学习模型训练前期,需要对数据、图像、文本等进行预处理,而如何快速生成数据的文本路径呢?本文接下来直接使用C++实现文本路径生成,可查找固定格式如.jpg
、.txt
等文件路径(绝对路径或文件名),然后保存为.txt
文本,方便后期图片数据读取使用。
C++代码实现如下:
#include <io.h>#include <fstreanm>#include <string>#include <vector>#include <iostream>using namespace std;void GetAllFiles(string path, vector<string>& files, string format) { long hfile = 0; struct _finddata_t fileinfo; //用来存储文件信息的结构体 string p; if(hfile = _findfirst(p.assign(path).append("\\*" + format).c_str(), &fileinfo)) != -1) //第一次查找 { do{ //files.push_back(p.assign(fileinfo.name)); //只保存文件名files.push_back(p.assign(path).appand("\\").append(fileinfo.name)); //保存文件路径和文件名 }while(_findnext(hfile, &fileinfo) == 0); _findclose(hfile) } else if((hfile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo)) != -1) { do{ if((fileinfo.attrib & _A_SUBDIR)) //如果查找到的是文件夹 { if(strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0) //进入文件夹查找 { GetAllFiles(p.assign(path).append("\\").append(fileinfo.name), files, format); } } else //如果查找的不是文件夹 { //files.push_back(p.assign(fileinfo.name)); //只保存文件名 files.push_back(p.assign(path).appand("\\").append(fileinfo.name)); //保存文件路径和文件名 } }while(_findnext(hfile, &fileinfo) == 0); _findclose(hfile) } }int main() { string filepath = "D:\\path..."; //文件根目录 vector<string> files; char *dstAll = "path.txt"; //读取所以格式为jpg的文件 string format = ".jpg"; GetAllFiles(filepath, files, format); ofstream ofn(distAll); int size = files.size(); for(int i = 0; i<size; i++) { ofn<<files[i]<<endl; //写入文件 cout<<files[i]<<endl; //输出到屏幕 } ofn.close(); cout<<"file number: "<<size<<endl; system("pause";) return 0; }
注意:如果format赋值出错会进入死循环。
相关文章:
The above is the detailed content of How to quickly generate the text path of data? C++ implements text path generation. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP data preprocessing functions can be used for type conversion, data cleaning, date and time processing. Specifically, type conversion functions allow variable type conversion (such as int, float, string); data cleaning functions can delete or replace invalid data (such as is_null, trim); date and time processing functions can perform date conversion and formatting (such as date, strtotime, date_format).

Overview of how to use Vue form processing to implement data preprocessing before form submission: In web development, forms are one of the most common elements. Before submitting the form, we often need to perform some preprocessing on the data entered by the user, such as format verification, data conversion, etc. The Vue framework provides convenient and easy-to-use form processing functions. This article will introduce how to use Vue form processing to implement data preprocessing before form submission. 1. Create a Vue instance and form control First, we need to create a Vue instance and define a containing table

Data Preprocessing Data preprocessing is a crucial step in the data analysis process. It involves cleaning and transforming data to make it suitable for analysis. Python's pandas library provides rich functionality to handle this task. Sample code: importpandasaspd#Read data from CSV file df=pd.read_csv("data.csv")#Handle missing values df["age"].fillna(df["age"].mean(),inplace=True )#Convert data type df["gender"]=df["gender"].astype("cateGory")Scik for machine learning Python

In modern software development, for most applications, it is necessary to be able to interact with various relational databases in order to be able to share data between the application and the database. MySQL is a widely used open source relational database management system, and the Go language is a modern programming language with excellent performance. It provides many built-in libraries to easily interact with the MySQL database. This article will explore how to use Go language to write prepared statements to improve the performance of MySQL database. What is preprocessing? Preprocessing is to make

Use PHP to develop and implement data preprocessing and compression transmission of Baidu Wenxin Yiyan API interface. With the development of the Internet, people have more and more demands for interfaces. The Baidu Wenxin Yiyan API interface is a very popular interface, which can provide some interesting sentences, famous sayings and aphorisms. In order to improve the efficiency and performance of the interface, we can perform some preprocessing and compression transmission on the interface data, thereby speeding up data transmission and reducing bandwidth usage. First, we need to apply for an APIKey on Baidu Open Platform. This

A Way to Implement Server-Side Rendering and Data Preprocessing in JavaScript In modern web applications, building high-performance and scalable websites has become increasingly important. Server-side rendering and data preprocessing are two key technologies to achieve this goal, and they can significantly improve the performance and responsiveness of the application. This article will introduce how to use JavaScript to implement server-side rendering and data preprocessing. Server-side rendering Server-side rendering refers to generating HTML code on the server side and sending it to

Python, as a commonly used programming language, can process and analyze a variety of different data. Data preprocessing is a very important and necessary step in data analysis. It includes steps such as data cleaning, feature extraction, data conversion and data standardization. The purpose of preprocessing is to improve the quality and analyzability of data. There are many data preprocessing techniques and tools available in Python. Some commonly used techniques and tools are introduced below. Data Cleaning In the data cleaning stage, we need to deal with missing values, duplicate values, and differences in some original data.

How to use VueRouter to implement data preprocessing before page jump? Introduction: When using Vue to develop single-page applications, we often use VueRouter to manage jumps between pages. Sometimes, we need to preprocess some data before jumping, such as obtaining data from the server, or verifying user permissions, etc. This article will introduce how to use VueRouter to implement data preprocessing before page jump. 1. Install and configure VueRouter First, we need to install Vu
