本文介绍了检查文件夹路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图检查指定的路径是否存在。

I'm trying to check if the path given exists. In case it doesn't, I'd like to create a folder with name given in the same directory.

我们假设pathOne:/ home / music / A和pathTwo:/ home / music / B,使得文件夹A存在,但是文件夹B不存在。如果用户给定的路径是pathOne,则不会发生任何事情,但如果它的pathTwo,则程序应该意识到它不存在于/ home中,并且应该创建它。

Let's say pathOne: "/home/music/A" and pathTwo: "/home/music/B", such that folder A exists but folder B doesn't. Nothing happens if the path given by the user is pathOne, but if its pathTwo, then the program should realize that it doesn't exist in /home and should create it.

我知道可以检查文件的存在(使用fopen它可能做到),但我不知道如何做的文件夹!

I know that it's possible to check the existence from files (with fopen it's possible do to that), but I don't know how to do that for folders!

推荐答案

您应该能够使用。它也是可移植的。

You should be able to use Boost Filesystem exists function. It's also portable.

有一个非常好的教程描述这个场景,名为

There is a very good tutorial describing this very scenario, named Using status queries to determine file existence and type - (tut2.cpp)

这篇关于检查文件夹路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 19:16