www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Long File path Exception:The system cannot find the path specified

reply Vino.B <vino.bheeman hotmail.com> writes:
Hi All,

   When i run the below code in windows i am getting "The system 
cannot find the path specified" even though the path exist , the 
length of the path is 516 as below, request your help.

Path :
N:\PROD_TEAM\TST_BACKUP\abcyf0\TST_BATS\j2ee_backup\cluster\states0\apps\bat.com\tc~bat~agent~application~e2emai~std~collectors\servlet_jsp\tc~bat~agent~application~e2emai~std~collectors\root\WEB-INF\entities\DataCollectionPushFileContentScannerTypeBuilder

Program:
void SizeDirList (string[] SzDNDlst)
{
  auto logF = File(LFpath, "a");
  ulong subdirTotal = 0;
  foreach (string i; SzDNDlst[0 .. $])
      {
       auto dFiles = dirEntries(i, SpanMode.shallow).filter!(a => 
a.isDir && !globMatch(a.baseName, "*DND*")).array;
	  foreach (d; dFiles)
	        {
				auto SdFiles = dirEntries(d, SpanMode.breadth).array;
				foreach (f; SdFiles)
					{
						subdirTotal += f.size;
					}
				   ulong subdirTotalGB = (subdirTotal/1024/1024/1024);
	               if (subdirTotalGB > SizeDir)
			            {
	     	                writefln("%-63s %s", d, subdirTotalGB);
				        }
						subdirTotal = 0;
		    }	
	 }
}

From,
Vino.B
Aug 22
next sibling parent reply Moritz Maxeiner <moritz ucworks.org> writes:
On Wednesday, 23 August 2017 at 05:06:50 UTC, Vino.B wrote:
 Hi All,

   When i run the below code in windows i am getting "The system 
 cannot find the path specified" even though the path exist , 
 the length of the path is 516 as below, request your help.

 Path :
 N:\PROD_TEAM\TST_BACKUP\abcyf0\TST_BATS\j2ee_backup\cluster\states0\apps\bat.com\tc~bat~agent~application~e2emai~std~collectors\servlet_jsp\tc~bat~agent~application~e2emai~std~collectors\root\WEB-INF\entities\DataCollectionPushFileContentScannerTypeBuilder

 Program:
 [...]
On which line do you get the Exception? Does it happen with shorter paths, as well? Assuming it happens with all paths: Just to be sure, is each of those backslashes actually encoded as a backslash? If you specified the path in the D source like `path = "N:\PROD_TEAM..."`, then it won't be, because backslash is an escape character (you would need to write `path = "N:\\PROD_TEAM..."`, or better yet path = "N:/PROD_TEAM..."`).
Aug 23
parent reply Vino.B <vino.bheeman hotmail.com> writes:
On Wednesday, 23 August 2017 at 11:29:07 UTC, Moritz Maxeiner 
wrote:
 On Wednesday, 23 August 2017 at 05:06:50 UTC, Vino.B wrote:
 Hi All,

   When i run the below code in windows i am getting "The 
 system cannot find the path specified" even though the path 
 exist , the length of the path is 516 as below, request your 
 help.

 Path :
 N:\PROD_TEAM\TST_BACKUP\abcyf0\TST_BATS\j2ee_backup\cluster\states0\apps\bat.com\tc~bat~agent~application~e2emai~std~collectors\servlet_jsp\tc~bat~agent~application~e2emai~std~collectors\root\WEB-INF\entities\DataCollectionPushFileContentScannerTypeBuilder

 Program:
 [...]
On which line do you get the Exception? Does it happen with shorter paths, as well? Assuming it happens with all paths: Just to be sure, is each of those backslashes actually encoded as a backslash? If you specified the path in the D source like `path = "N:\PROD_TEAM..."`, then it won't be, because backslash is an escape character (you would need to write `path = "N:\\PROD_TEAM..."`, or better yet path = "N:/PROD_TEAM..."`).
Hi, The above program scan for files/directories under the main folder N:\PROD_TEAM\ and reports the size of each of the sub folders eg: "TST_BACKUP", under the main folder "N:\PROD_TEAM\" there are more than 9000+ files/directories, eg: (N:\PROD_TEAM\TST_BACKUP,N:\PROD_TEAM\PRD_BACKUP\....) and the above program will output the size of the sub folders "TST_BACKUP,PRD_BACKUP", there is no issue is the path is shorter, the issue arises only when the path is bigger, eg the program prints the size of the sub folder PRD_BACKUP but when it tries to scan the sub folder TST_BACKUP the issue arises and the program terminates with the exception "The system cannot find the path specified", hence it not not be possible to provide the path explicitly, so can you help me on this. From, Vino.B
Aug 23
parent reply Moritz Maxeiner <moritz ucworks.org> writes:
On Wednesday, 23 August 2017 at 12:01:20 UTC, Vino.B wrote:
 On Wednesday, 23 August 2017 at 11:29:07 UTC, Moritz Maxeiner 
 wrote:
 On which line do you get the Exception? Does it happen with 
 shorter paths, as well?
 Assuming it happens with all paths: Just to be sure, is each 
 of those backslashes actually encoded as a backslash? If you 
 specified the path in the D source like `path = 
 "N:\PROD_TEAM..."`, then it won't be, because backslash is an 
 escape character (you would need to write `path = 
 "N:\\PROD_TEAM..."`, or better yet path = "N:/PROD_TEAM..."`).
The above program scan for files/directories under the main folder N:\PROD_TEAM\ and reports the size of each of the sub folders eg: "TST_BACKUP", under the main folder "N:\PROD_TEAM\" there are more than 9000+ files/directories, eg: (N:\PROD_TEAM\TST_BACKUP,N:\PROD_TEAM\PRD_BACKUP\....) and the above program will output the size of the sub folders "TST_BACKUP,PRD_BACKUP", there is no issue is the path is shorter, the issue arises only when the path is bigger, eg the program prints the size of the sub folder PRD_BACKUP but when it tries to scan the sub folder TST_BACKUP the issue arises and the program terminates with the exception "The system cannot find the path specified", hence it not not be possible to provide the path explicitly, so can you help me on this.
While that is good to know, you still haven't answered my initial question:
 On which line do you get the Exception?
If your program terminates because of an uncaught exception (as you stated), then you should've received a stack trace containing the line number on which the exception was thrown (remember to compile with debug info). You should also consider providing a compilable, minimal example (with test data) that can be used to reproduce the issue.
Aug 23
parent reply Vino.B <vino.bheeman hotmail.com> writes:
On Wednesday, 23 August 2017 at 12:12:47 UTC, Moritz Maxeiner 
wrote:
 On Wednesday, 23 August 2017 at 12:01:20 UTC, Vino.B wrote:
 On Wednesday, 23 August 2017 at 11:29:07 UTC, Moritz Maxeiner 
 wrote:
 On which line do you get the Exception? Does it happen with 
 shorter paths, as well?
 Assuming it happens with all paths: Just to be sure, is each 
 of those backslashes actually encoded as a backslash? If you 
 specified the path in the D source like `path = 
 "N:\PROD_TEAM..."`, then it won't be, because backslash is an 
 escape character (you would need to write `path = 
 "N:\\PROD_TEAM..."`, or better yet path = "N:/PROD_TEAM..."`).
The above program scan for files/directories under the main folder N:\PROD_TEAM\ and reports the size of each of the sub folders eg: "TST_BACKUP", under the main folder "N:\PROD_TEAM\" there are more than 9000+ files/directories, eg: (N:\PROD_TEAM\TST_BACKUP,N:\PROD_TEAM\PRD_BACKUP\....) and the above program will output the size of the sub folders "TST_BACKUP,PRD_BACKUP", there is no issue is the path is shorter, the issue arises only when the path is bigger, eg the program prints the size of the sub folder PRD_BACKUP but when it tries to scan the sub folder TST_BACKUP the issue arises and the program terminates with the exception "The system cannot find the path specified", hence it not not be possible to provide the path explicitly, so can you help me on this.
While that is good to know, you still haven't answered my initial question:
 On which line do you get the Exception?
If your program terminates because of an uncaught exception (as you stated), then you should've received a stack trace containing the line number on which the exception was thrown (remember to compile with debug info). You should also consider providing a compilable, minimal example (with test data) that can be used to reproduce the issue.
The line it complains is std.file.FileException std\file.d(3713): even after enabling debug it points to the same Output: D:\DScript>rdmd -debug Test.d -r dryrun std.file.FileException std\file.d(3713): N:\PROD_TEAM\TST_BACKUP\abcyf0\TST_BATS\j2ee_backup\cluster\states0\apps\bat.com\tc~bat~agent~application~e2emai~std~collectors\servlet_jsp\tc~bat~agent~application~e2emai~std~collectors\root\WEB-INF\entities\DataCollectionPushFileConten ScannerTypeBuilder: The system cannot find the path specified. ---------------- 0x00431A56 0x00429801 From, Vino.B
Aug 23
parent reply Moritz Maxeiner <moritz ucworks.org> writes:
On Wednesday, 23 August 2017 at 13:04:28 UTC, Vino.B wrote:
 The line it complains is 
 std.file.FileException std\file.d(3713):even after enabling 
 debug it points to the same

 Output:
 D:\DScript>rdmd -debug Test.d -r  dryrun

 std.file.FileException std\file.d(3713): 
 N:\PROD_TEAM\TST_BACKUP\abcyf0\TST_BATS\j2ee_backup\cluster\states0\apps\bat.com\tc~bat~agent~application~e2emai~std~collectors\servlet_jsp\tc~bat~agent~application~e2emai~std~collectors\root\WEB-INF\entities\DataCollectionPushFileConten
ScannerTypeBuilder: The system cannot find the path specified.
 ----------------
 0x00431A56
 0x00429801
You need to compile with debug info (option `-g`), not compile in debug code (option `-debug`). What's the (full) stack trace when compiling with debug info?
Aug 23
parent reply Vino.B <vino.bheeman hotmail.com> writes:
On Wednesday, 23 August 2017 at 13:14:31 UTC, Moritz Maxeiner 
wrote:
 On Wednesday, 23 August 2017 at 13:04:28 UTC, Vino.B wrote:
 The line it complains is 
 std.file.FileException std\file.d(3713):even after enabling 
 debug it points to the same

 Output:
 D:\DScript>rdmd -debug Test.d -r  dryrun

 std.file.FileException std\file.d(3713): 
 N:\PROD_TEAM\TST_BACKUP\abcyf0\TST_BATS\j2ee_backup\cluster\states0\apps\bat.com\tc~bat~agent~application~e2emai~std~collectors\servlet_jsp\tc~bat~agent~application~e2emai~std~collectors\root\WEB-INF\entities\DataCollectionPushFileConten
ScannerTypeBuilder: The system cannot find the path specified.
 ----------------
 0x00431A56
 0x00429801
You need to compile with debug info (option `-g`), not compile in debug code (option `-debug`). What's the (full) stack trace when compiling with debug info?
Hi, Please find the output and the entire program below after executing with option -g. XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Program: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX import std.file: dirEntries, isFile, SpanMode, remove, rmdirRecurse, exists, mkdir; import std.stdio: writeln, writefln, File; import std.algorithm: filter; import std.array: array; import std.path: globMatch, baseName; /**********************************************/ /* Global Valiables */ /**********************************************/ int SizeDir = 10; /**********************************************/ /* Folder Lists */ /**********************************************/ auto SizeDirlst = [ "N:\\PROD_TEAM", "P:\\TEAM" ]; /******************************************/ /* Function : Size of Non DND Dir List */ /******************************************/ void SizeDirList (string[] SzDNDlst) { ulong subdirTotal = 0; foreach (string i; SzDNDlst[0 .. $]) { auto dFiles = dirEntries(i, SpanMode.shallow).filter!(a => a.isDir && !globMatch(a.baseName, "*DND*")).array; foreach (d; dFiles) { auto SdFiles = dirEntries(d, SpanMode.breadth).array; foreach (f; SdFiles) { subdirTotal += f.size; } ulong subdirTotalGB = (subdirTotal/1024/1024/1024); if (subdirTotalGB > SizeDir) { writefln("%-63s %s", d, subdirTotalGB); } subdirTotal = 0; } } } /********************************************************************************************/ /* Main */ /********************************************************************************************/ void main () { SizeDirList(SizeDirlst); } XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Output: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX D:\\DScript>rdmd -g Test.d -r dryrun N:\PROD_TEAM\PREBACKUP 97 N:\PROD_TEAM\TST_BACKUP\abcyf0\TST_BATS\j2ee_backup\cluster\states0\apps\bat.com\tc~bat~agent~application~e2emai~std~collectors\servlet_jsp\tc~bat~agent~application~e2emai~std~collectors\root\WEB-INF\entities\DataCollectionPushFileConten ScannerTypeBuilder: The system cannot find the path specified. ---------------- 0x00415742 in safe bool std.file.cenforce!(bool).cenforce(bool, lazy const(char)[], immutable(char)[], uint) 0x0040EA79 in void std.file.DirIteratorImpl.popFront() 0x00404948 in void std.array.Appender!(std.file.DirEntry[]).Appender.put!(std.file.DirEntry).pu (std.file.DirEntry) at C:\D\dmd2\windows\bin\..\ ..\src\phobos\std\array.d(2919) 0x00404B94 in std.file.DirEntry[] std.array.array!(std.file.DirIterator).array(std.file.DirIterator) at C:\D\dmd2\windows\bin\..\..\src\phobos\s td\array.d(137) 0x00402363 in void Size.SizeDirList(immutable(char)[][]) at D:\DScript\Test.d(26) 0x00402468 in _Dmain at D:\DScript\Test.d(46) 0x0040E323 in D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv 0x0040E2E7 in void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll() 0x0040E1E8 in _d_run_main 0x0040DCB8 in main at D:\DScript\Test.d(7) 0x00459DA9 in mainCRTStartup 0x75CE336A in BaseThreadInitThunk 0x775F9902 in RtlInitializeExceptionChain 0x775F98D5 in RtlInitializeExceptionChain Lines in the script. D:\DScript\Test.d(26) : auto SdFiles = dirEntries(d, SpanMode.breadth).array; D:\DScript\Test.d(46) : SizeDirList(SizeDirlst); D:\DScript\Test.d(7) : /* Global Valiables */ From, Vino.B
Aug 23
parent reply Vino.B <vino.bheeman hotmail.com> writes:
On Wednesday, 23 August 2017 at 13:50:18 UTC, Vino.B wrote:
 On Wednesday, 23 August 2017 at 13:14:31 UTC, Moritz Maxeiner 
 wrote:
 [...]
Hi, [...]
Hi, Any idea of what is causing this issue.
Aug 24
parent reply vino <vino.bheeman hotmail.com> writes:
On Thursday, 24 August 2017 at 12:16:22 UTC, Vino.B wrote:
 On Wednesday, 23 August 2017 at 13:50:18 UTC, Vino.B wrote:
 On Wednesday, 23 August 2017 at 13:14:31 UTC, Moritz Maxeiner 
 wrote:
 [...]
Hi, [...]
Hi, Any idea of what is causing this issue.
Hi, Thanks for your support, was able to resolve this issue. From, Vino.B
Aug 24
parent reply zabruk70 <sorry noem.ail> writes:
On Thursday, 24 August 2017 at 18:02:24 UTC, vino wrote:
   Thanks for your support, was able to resolve this issue.
Hello. IMHO, it will be better, if you will share your solution for other peoples :)
Aug 25
parent Vino.B <vino.bheeman hotmail.com> writes:
On Friday, 25 August 2017 at 09:08:44 UTC, zabruk70 wrote:
 On Thursday, 24 August 2017 at 18:02:24 UTC, vino wrote:
   Thanks for your support, was able to resolve this issue.
Hello. IMHO, it will be better, if you will share your solution for other peoples :)
Hi, Please find the solution below, basically i converted the path to UNC path as below Solution: auto unc = "\\\\?\\"~i; auto dFiles = dirEntries(unc, SpanMode.shallow).filter!(a => a.isDir && !globMatch(a.baseName, "*DND*")).array; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Program: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX import std.file: dirEntries, isFile, SpanMode, remove, rmdirRecurse, exists, mkdir; import std.stdio: writeln, writefln, File; import std.algorithm: filter; import std.array: array; import std.path: globMatch, baseName; /**********************************************/ /* Global Valiables */ /**********************************************/ int SizeDir = 10; /**********************************************/ /* Folder Lists */ /**********************************************/ auto SizeDirlst = [ "N:\\PROD_TEAM", "P:\\TEAM" ]; /******************************************/ /* Function : Size of Non DND Dir List */ /******************************************/ void SizeDirList (string[] SzDNDlst) { ulong subdirTotal = 0; foreach (string i; SzDNDlst[0 .. $]) { auto unc = "\\\\?\\"~i; auto dFiles = dirEntries(unc, SpanMode.shallow).filter!(a => a.isDir && !globMatch(a.baseName, "*DND*")).array; foreach (d; dFiles) { auto SdFiles = dirEntries(d, SpanMode.breadth).array; foreach (f; SdFiles) { subdirTotal += f.size; } ulong subdirTotalGB = (subdirTotal/1024/1024/1024); if (subdirTotalGB > SizeDir) { writefln("%-63s %s", d[0].replace("\\\\?\\", ""), subdirTotalGB); } subdirTotal = 0; } } } /********************************************************************************************/ /* Main */ /********************************************************************************************/ void main () { SizeDirList(SizeDirlst); }
Aug 25
prev sibling parent Mike Parker <aldacron gmail.com> writes:
On Wednesday, 23 August 2017 at 05:06:50 UTC, Vino.B wrote:
 Hi All,

   When i run the below code in windows i am getting "The system 
 cannot find the path specified" even though the path exist , 
 the length of the path is 516 as below, request your help.

 Path :
 N:\PROD_TEAM\TST_BACKUP\abcyf0\TST_BATS\j2ee_backup\cluster\states0\apps\bat.com\tc~bat~agent~application~e2emai~std~collectors\servlet_jsp\tc~bat~agent~application~e2emai~std~collectors\root\WEB-INF\entities\DataCollectionPushFileContentScannerTypeBuilder

 Program:
 void SizeDirList (string[] SzDNDlst)
 {
  auto logF = File(LFpath, "a");
  ulong subdirTotal = 0;
  foreach (string i; SzDNDlst[0 .. $])
      {
       auto dFiles = dirEntries(i, SpanMode.shallow).filter!(a 
 => a.isDir && !globMatch(a.baseName, "*DND*")).array;
 	  foreach (d; dFiles)
 	        {
 				auto SdFiles = dirEntries(d, SpanMode.breadth).array;
 				foreach (f; SdFiles)
 					{
 						subdirTotal += f.size;
 					}
 				   ulong subdirTotalGB = (subdirTotal/1024/1024/1024);
 	               if (subdirTotalGB > SizeDir)
 			            {
 	     	                writefln("%-63s %s", d, subdirTotalGB);
 				        }
 						subdirTotal = 0;
 		    }	
 	 }
 }

 From,
 Vino.B
Windows has a 260-character limit on file path names. This can be disabled in Windows 10 for applications that ship with a manifest, but that isn't going to help you. If the Phobos functions are using the Win32 API internally, and specifically the Unicode variants, then you should be able to get around this by prepending "\\?" to any file path you send to the API. That's how long file paths have been handled in Win32 to date. If it doesn't work with Phobos, then you'll need to call Win32 directly and Phobos should be modified.
Aug 23