c# - Unable to delete a desktop folder -


problem: unable delete folder (including contents) within desktop folder programatically c#. if copy value of desktopdestinationpath , paste windows explorer, can open folder (conclusion, path valid) test - directory.exists(desktopdestinationpath) - returns true , drop code block (conclusion, path valid) directory.delete(desktopdestinationpath, true) - throws exception (conclusion, path no longer valid) if copy path value exception , paste windows explorer, can open folder (conclusion, path valid)

what have tried: build, rebuild, clean solution, restart visual studio. also, if delete folder manually , run code, folder built. however, when run second time, exception. result: puzzled , post. sorry if put detail. open solution , criticism on how posted (both me learn) in advance! visual studio info toward bottom of entry. using: microsoft visual studio premium 2013 (c#).

my code:

    // preceded other code in method     if (directory.exists(desktopdestinationpath)) // desktopdestinationpath "c:\\users\<me>\\desktop\\<folder 1>\\<folder 2>"     {         directory.delete(desktopdestinationpath, true); // exception thrown here <***> "c:\\users\\<me>\\desktop\\<folder 1>\\<folder 2>"                     // create folder         directory.createdirectory(desktopdestinationpath);         // call method perform xcopy         processxcopy(sourceloc, desktopdestinationpath);     }     // followed else creates folder if not exist 

my code throwing following exception: // note using pri.longpath

system.io.directorynotfoundexception unhandled user code hresult=-2147024893 message=could not find part of path 'c:\users\ljones\desktop\folder 1\folder2\fldr3\fldr4\fldr5\fldr6\fldr7\fldr8\fldr9'. source=mscorlib stacktrace: @ system.io.directory.deletehelper(string fullpath, string userpath, boolean recursive, boolean throwontopleveldirectorynotfound) @ system.io.directory.delete(string fullpath, string userpath, boolean recursive, boolean checkhost) @ system.io.directory.delete(string path, boolean recursive) @ unittests.gatminertest.createdesktopdestinationfolder(string desktoppath) in c:\users\some folder\source\workspaces\some folder\some folder\some folder\some file:line 93 @ unittests.gatminertest.icwintegrationmethod() in c:\users\some folder\source\workspaces\some folder\some folder\some folder\some file:line 65 innerexception:

from web have learned: directorynotfoundexception exception thrown when part of file path or directory not found. verify directory appears in specified location. check directory exists in specified location. // (99.9%) directory exists when using relative paths, make sure current directory correct. path may incorrect if assuming incorrect current directory. // (99.9%) directory exists

thank in finding answer. specifically, tips on posting question in more appropriate manner.

the solution error on part (go figure).

in code did not disclose, there call xcopy. believe during testing, had ran past point , xcopy working in background (still had hooks folder structure). therefore, couldn't delete it.

my apologies if wasted time. nudges helped push me toward finding error in ways.

thanks again!


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -