Fwd: Boost::Filesystem - How to iterate, through the whole drive
---------- Forwarded message ---------
From: Richard Závodný
On Sun, 18 Nov 2018 at 05:31, Richard Závodný via Boost-users < boost-users@lists.boost.org> wrote:
---------- Forwarded message --------- From: Richard Závodný
Date: Sat, Nov 17, 2018, 3:59 PM Subject: Boost::Filesystem - How to iterate, through the whole drive To: Hey guys, I need iterate over all directories from starting path. If I start iterating from C:\some-dir it works very well, however if I try to iterate from C:\, it doesn't work. How can iterate through the whole drive? Thank you.
Code is here: https://pastebin.com/mpsKJxH2 https://pastebin.com/3J6FEMG5. The problem I experience is commented right in the code section (line 1, 13 and 25).
This works for me, either with boost-1.68 (not that I think that matters)
or the STL-VC-15.9.1 (/std:c++17):
#include <iostream>
#include
I just wanna try it again here, maybe somebody will shop up who knows where is the problem as I unfortunately couldn't fix it with degski (but still, thank you for your time :)). His example (can be found below) doesn't work on my system. The problem is I can't start iteration from the drive root (for example E:\), because it will iterate only the directory above (E:\projects\boost\build) the directory that the executable is located in (the executable is located in E:\projects\boost\build\Debug). What is weird that if I move the executable to the different directory (let's say C:\Users\USER_NAME\Downloads) it will still iterate only the build directory. I tried to play with Visual Studio -> PROJECT_NAME -> Properties -> Debugging -> Working Directory, but without a success. According to degski he has the value of this entry set to $(ProjectDir) which is the same value as mine. Thank you. On 11/18/2018 9:04 AM, degski wrote:
On Sun, 18 Nov 2018 at 05:31, Richard Závodný via Boost-users
mailto:boost-users@lists.boost.org> wrote: ---------- Forwarded message --------- From: *Richard Závodný*
mailto:zavodnyrichard@gmail.com> Date: Sat, Nov 17, 2018, 3:59 PM Subject: Boost::Filesystem - How to iterate, through the whole drive To: mailto:boost-users@lists.boost.org> Hey guys, I need iterate over all directories from starting path. If I start iterating from C:\some-dir it works very well, however if I try to iterate from C:\, it doesn't work. How can iterate through the whole drive? Thank you.
Code is here: https://pastebin.com/mpsKJxH2 https://pastebin.com/3J6FEMG5. The problem I experience is commented right in the code section (line 1, 13 and 25).
This works for me, either with boost-1.68 (not that I think that matters) or the STL-VC-15.9.1 (/std:c++17):
#include <iostream> #include
namespace fs = boost::filesystem;
int main ( ) { for ( auto & p : fs::recursive_directory_iterator ( "d:\\" ) ) { std::cout << p.path ( ) << '\n'; } }
Note that: "The iteration order is unspecified, except that each directory entry is visited only once."
degski -- /*/*“*/If something cannot go on forever, it will stop" - Herbert Stein*/
Richard Závodný via Boost-users wrote:
I just wanna try it again here, maybe somebody will shop up who knows where is the problem as I unfortunately couldn't fix it with degski (but still, thank you for your time :)). His example (can be found below) doesn't work on my system.
Hi Richard, Try running your console app as administrator outside of VS. This really can have nothing to do with boost::filesystem as the first API call is '::FindFirstFileW'. So it is the operating system that is limiting the access to your app. I did a little searching but could find nothing about VS settings. I do always run VS as administrator though. It keeps such things from happening. Best, Dan.
Thank you, looks like you were right. I ran it outside Visual Studio with admin rights, but when I ran it in Visual Studio developer console (also with admin rights) before (when I tried to solve it with degski), I couldn't manage to make it work. Right now it looks like problem is solved, but it is weird it needs administrator rights, as I can iterate subdirectory on that specific drive (E:) without them. Weird. Thank you both for your time. :) On Mon, Nov 19, 2018, 9:55 PM Dan Bloomquist via Boost-users < boost-users@lists.boost.org wrote:
Richard Závodný via Boost-users wrote:
I just wanna try it again here, maybe somebody will shop up who knows where is the problem as I unfortunately couldn't fix it with degski (but still, thank you for your time :)). His example (can be found below) doesn't work on my system.
Hi Richard, Try running your console app as administrator outside of VS. This really can have nothing to do with boost::filesystem as the first API call is '::FindFirstFileW'. So it is the operating system that is limiting the access to your app. I did a little searching but could find nothing about VS settings. I do always run VS as administrator though. It keeps such things from happening. Best, Dan.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org https://lists.boost.org/mailman/listinfo.cgi/boost-users
On Tue, 20 Nov 2018 at 15:16, Richard Závodný via Boost-users < boost-users@lists.boost.org> wrote:
Thank you, looks like you were right. I ran it outside Visual Studio with admin rights, but when I ran it in Visual Studio developer console (also with admin rights) before (when I tried to solve it with degski), I couldn't manage to make it work. Right now it looks like problem is solved, but it is weird it needs administrator rights, as I can iterate subdirectory on that specific drive (E:) without them. Weird. Thank you both for your time. :)
Got it now! Win10 is particularly picky about running stuff [or changing/deleting files] in the root of drives [less so about doing the same thing in folders], and always asks for elevated privileges [even though it shouldn't, as I've turned that off in UAC]. I can run the [any] program simply from within the IDE. I now realized that I [always] run VS20XX with elevated rights [through a short-cut], so that this problem does not show up [I must have run into this already (long time ago), I guess]. You can change the elevation of the short-cut [and therefor the program] by right-clicking the shortcut, Properties -> Shortcut -> Advanced (button), tick the box "Run as administrator" -> OK. This way it will simply run from the IDE and you'll be able to debug as well. degski -- *“If something cannot go on forever, it will stop" - Herbert Stein*
Thank you, it makes sense now. :) On 11/20/2018 2:46 PM, degski wrote:
On Tue, 20 Nov 2018 at 15:16, Richard Závodný via Boost-users
mailto:boost-users@lists.boost.org> wrote: Thank you, looks like you were right. I ran it outside Visual Studio with admin rights, but when I ran it in Visual Studio developer console (also with admin rights) before (when I tried to solve it with degski), I couldn't manage to make it work. Right now it looks like problem is solved, but it is weird it needs administrator rights, as I can iterate subdirectory on that specific drive (E:) without them. Weird. Thank you both for your time. :)
Got it now! Win10 is particularly picky about running stuff [or changing/deleting files] in the root of drives [less so about doing the same thing in folders], and always asks for elevated privileges [even though it shouldn't, as I've turned that off in UAC].
I can run the [any] program simply from within the IDE. I now realized that I [always] run VS20XX with elevated rights [through a short-cut], so that this problem does not show up [I must have run into this already (long time ago), I guess].
You can change the elevation of the short-cut [and therefor the program] by right-clicking the shortcut, Properties -> Shortcut -> Advanced (button), tick the box "Run as administrator" -> OK. This way it will simply run from the IDE and you'll be able to debug as well.
degski -- /*/*“*/If something cannot go on forever, it will stop" - Herbert Stein*/
As an aside, thanks for posting this as I wasn't previous aware of recursive_directory_iterator and have been implementing the recursion myself. Pete On Tue, 20 Nov 2018 at 15:44, Richard Závodný via Boost-users < boost-users@lists.boost.org> wrote:
Thank you, it makes sense now. :) On 11/20/2018 2:46 PM, degski wrote:
On Tue, 20 Nov 2018 at 15:16, Richard Závodný via Boost-users < boost-users@lists.boost.org> wrote:
Thank you, looks like you were right. I ran it outside Visual Studio with admin rights, but when I ran it in Visual Studio developer console (also with admin rights) before (when I tried to solve it with degski), I couldn't manage to make it work. Right now it looks like problem is solved, but it is weird it needs administrator rights, as I can iterate subdirectory on that specific drive (E:) without them. Weird. Thank you both for your time. :)
Got it now! Win10 is particularly picky about running stuff [or changing/deleting files] in the root of drives [less so about doing the same thing in folders], and always asks for elevated privileges [even though it shouldn't, as I've turned that off in UAC].
I can run the [any] program simply from within the IDE. I now realized that I [always] run VS20XX with elevated rights [through a short-cut], so that this problem does not show up [I must have run into this already (long time ago), I guess].
You can change the elevation of the short-cut [and therefor the program] by right-clicking the shortcut, Properties -> Shortcut -> Advanced (button), tick the box "Run as administrator" -> OK. This way it will simply run from the IDE and you'll be able to debug as well.
degski -- *“If something cannot go on forever, it will stop" - Herbert Stein*
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org https://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (4)
-
Dan Bloomquist
-
degski
-
Peter Barker
-
Richard Závodný