uwekeim / zetalongpaths Goto Github PK
View Code? Open in Web Editor NEWA .NET library to access files and directories with more than 260 characters length.
Home Page: https://nuget.org/packages/ZetaLongPaths
License: MIT License
A .NET library to access files and directories with more than 260 characters length.
Home Page: https://nuget.org/packages/ZetaLongPaths
License: MIT License
when use ZlpFileInfo(path).OpenRead() or ZlpFileInfo(path).OpenWrite() when pass the file path does not exist, it will create a new file with the same path and file name provided, this is wrong does not meet the expected as System.IO.File.Open(path, FileMode.Open, System.IO.FileAccess.Read) or System.IO.File.Open(path, FileMode.Open, System.IO.FileAccess.ReadWrite).
but when using System.IO.File.Open(path, FileMode.Open, System.IO.FileAccess.Read) and pass file path does not exist will be return exception could not find the path provided.
I need the same as System.IO.File.Open(path, FileMode.Open, System.IO.FileAccess.Read) if possible.
I am using zeta long paths nuget package with v1.0.0.16 . i am getting path too long exception when i try to read the file. I am able to fetch the files information but unable to read the file.
It's a good practice to provide license information together with NuGet Package so it is available in nuspec file.
How to get GetDirectoryRoot() in ZetaLongPath?
such as System.IO.Directory.GetDirectoryRoot(_path)
When calling ZlpPathHelper.GetFileNameWithoutExtension
with a filename without extension,
the function is returning an empty string.
The correct return value should be the whole filename, as it doesn't contain extension.
if path starts with "\\?\" the ZlpPathHelper.IsAbsolute method returns always false.
var absolutePath = ZlpPathHelper.GetAbsolutePath(longRelativeFilePath, longBasePath);
// absolutePath has prefix \\\\?\\
var isAbsolutePath = ZlpPathHelper.IsAbsolutePath(absolutePath);
//isAbsolutePath is false ;(
There is a typo in the sample code in the readme
var folderPath = new ZetaDirectoryInfo( @"C:\My\Long\Folder\Path" );
ZetaDirectoryInfo is not found! but ZlpDirectoryInfo is!
Guessing some refactoring has been done ;-)
Thanks for a really nice library!
As the title says:
ZlpDirectoryInfo dirInfo1 = new ZlpDirectoryInfo(@"C:\Foo\Bar");
Console.WriteLine(dirInfo1.Name); //"Bar"
ZlpDirectoryInfo dirInfo2 = new ZlpDirectoryInfo(@"C:\Foo\Bar\");
Console.WriteLine(dirInfo2.Name); //"", an empty string
Hello,
I think this is an easy Question : What is the expected pattern format ? The .NET Standard GetFiles()
function takes a string array.
The ZLP Libary is expecting a regular string.
How do I specify multiple file extension , for example "*.pdf, *.jpg, *.docx"?
Public Function GetFiles(pattern As String, searchOption As SearchOption) As ZlpFileInfo()
Great Library! Well Done!
I need to know if the IZlpFileSystemInfo same as System.IO.FileSystemInfo?
When using in System.IO
FileSystemInfo BLFileInf = (FileSystemInfo)(new FileInfo(sBlockFile));
in zeta
IZlpFileSystemInfo BLFileInf = (IZlpFileSystemInfo)(new ZlpFileInfo(sBlockFile));
above is same?!
I am using this package in my project at https://github.com/taori/VolumeScanner2/tree/bugfix/performanceoptimization
However after a lot of Performance optimization i came to a point where the hot path are the two methods in the title - Do you think there is any way those methods could be sped up anymore or is it just slow by nature of things?
on a m2ssd scanning 150gb recursively takes 27 seconds. Does that seem reasonable or is there room for more performance?
I have been able to create files on a network path (ex: \\my.net.foo\some\long\path\bar.txt
) but then I encounter 2 problems:
Z:\long\path\bar.txt
, where Z:
is \\my.net.foo\some
), the returned path is always longer than the original path.Some additionnal info:
C:\
)I'm thinking it may have to do with the protocol used for the network file system as described here but other than that I'm clueless. If that truly is the problem (I don't have the info concerning what technology is used yet) then there's not much I can do.
Am I on the right track or am I missing something?
How to get IsPathRooted in ZetaLongPath?
such as System.IO.Path.IsPathRooted(_path) return boolean true or false.
There is an exception when ZetaLongPaths moves files from long source path on Windows Server 2012. Operating system is up to date. Source path + name of file limit is 256 chars, after this length the problem starts to occur.
Method:
ZlpIOHelper.MoveFile(source, destination);
Exception:
System.ComponentModel.Win32Exception (0x80004005): Error 123 moving file
'\\?\C:\Program Files (x86)\xxxx.txt'
to'\\?\D:\xxxxx.txt'
: The filename, directory name, or volume label syntax is incorrect.
at ZetaLongPaths.ZlpIOHelper.MoveFile(String sourceFilePath, String destinationFilePath, Boolean overwriteExisting) in c:\P\ZetaLongPaths\Source\RuntimeNetCore\ZlpIOHelper.cs:line 489
Is there any solution to this problem?
windows convert the long path to a short path using Tilde "~" for example:
return from windows:
C:\HOTLON1\TESTLO1\NEWFOL1\MAAAAA1\ROOOOO1\ALLLLL1\QAAAAA1\ORIGIN1\TESTTT1\test221\HOTLON1.PNG
the original path:
C:\HOTLongPathTEST\TestLongPathhhhhhh211\Newfolder11\Maaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaain11\Roooooooooooooooooooooooooooooooooooooooooooooooot11\ALLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL11\QAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrrtttttttttttttttttttttttttttttttttttt11\originallllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll11\testttt111\test221\HotLongtest.png
when pass the windows return path to the zeta file info and check if zlpFileInfo.Exists or not always returns Exists = False and zlpFileInfo.FullName returns the short path as windows.
string _Path = "LongPath";
System.IO.FileStream oReader = ZetaLongPaths.ZlpFileInfo(_Path).OpenRead();
not work on windows 8.1 almost return 0 bytes when read and when call windows error after this line return error (183) meaning:
ERROR_ALREADY_EXISTS
183 (0xB7)
Cannot create a file when that file already exists.
Note: the writer works fine on the same long path.
the same code works fine on the short path.
what is the problem?
When use ZlpPathHelper.Combine(path1, path2) function not return the same as System.IO.Path.Combine(path1, path2).
For example when use System.IO.Path.Combine(path1, path2):
System.IO.Path.Combine("C:\Users\m.ahmad\AppData\Roaming\MustafaDaoud\MustafaDaoud\Jobs\{6E820F39-1F0F-4C22-A9F6-5E7CAE6F6FA7}\Data\BackupCache\","C:\Users\m.ahmad\AppData\Roaming\MustafaDaoud\MustafaDaoud\Jobs\{6E820F39-1F0F-4C22-A9F6-5E7CAE6F6FA7}\Data\BackupCache\9219909703685094454.pst")
returns this path:
C:\Users\m.ahmad\AppData\Roaming\MustafaDaoud\MustafaDaoud\Jobs{6E820F39-1F0F-4C22-A9F6-5E7CAE6F6FA7}\Data\BackupCache\3948766359955674179.pst
but when use ZlpPathHelper.Combine(path1, path2):
ZlpPathHelper.Combine("C:\Users\m.ahmad\AppData\Roaming\MustafaDaoud\MustafaDaoud\Jobs\{6E820F39-1F0F-4C22-A9F6-5E7CAE6F6FA7}\Data\BackupCache\","C:\Users\m.ahmad\AppData\Roaming\MustafaDaoud\MustafaDaoud\Jobs\{6E820F39-1F0F-4C22-A9F6-5E7CAE6F6FA7}\Data\BackupCache\9219909703685094454.pst")
returns this path:
C:\Users\m.ahmad\AppData\Roaming\MustafaDaoud\MustafaDaoud\Jobs{6E820F39-1F0F-4C22-A9F6-5E7CAE6F6FA7}\Data\BackupCache\C:\Users\m.ahmad\AppData\Roaming\MustafaDaoud\MustafaDaoud\Jobs{6E820F39-1F0F-4C22-A9F6-5E7CAE6F6FA7}\Data\BackupCache\3948766359955674179.pst
please advise.
Hi I just tried the library, and I am not sure i am using it correctly or not. but I am always getting Error
Code 3
I am using VS2015, Platform 4.6 c#, Please advise
ZetaLongPaths.ZlpIOHelper.CopyFile(path, ZetaLongPaths.ZlpPathHelper.GetFullPath(newpath), true);
'ZetaLongPaths.ZlpIOHelper.CopyFile(path, ZetaLongPaths.ZlpPathHelper.GetFullPath(newpath), true)' threw an exception of type 'System.ComponentModel.Win32Exception'
Data: {System.Collections.ListDictionaryInternal}
ErrorCode: -2147467259
HResult: -2147467259
HelpLink: null
InnerException: null
Message: "Error 3 copying file '\\?\C:\Moustafa\Revit_API\Projects\Future2017\External_Projects\ID_Organizer\ID_Organizer\bin\Debug\C\Users\gaj.guest\AppData\Local\Temp\Re 3335- Specialty restaurant termination_00000000A002257DE017F94A9DFF97681AB4924907008340FEB4941DD34FBE4C185A697EC9990000002FAE8F0000EFB46473E332FE4FA6BC3D27BC0EBF2A0001C40DBE040000.msg' to 'D:\for construction\ID-Organizer\ExtraDoc\SR\Re 3335- Specialty restaurant termination_00000000A002257DE017F94A9DFF97681AB4924907008340FEB4941DD34FBE4C185A697EC9990000002FAE8F0000EFB46473E332FE4FA6BC3D27BC0EBF2A0001C40DBE040000.msg': The system cannot find the path specified."
NativeErrorCode: 3
Source: "ZetaLongPaths"
StackTrace: " at ZetaLongPaths.ZlpIOHelper.CopyFile(String sourceFilePath, String destinationFilePath, Boolean overwriteExisting) in c:\P\ZetaLongPaths\Source\RuntimeNetCore\ZlpIOHelper.cs:line 414"
TargetSite: {Void CopyFile(System.String, System.String, Boolean)}
After deleted file when using ZetaLongPaths.ZlpIOHelper.GetFileAttributes(_Path) to get the file attribute and check if hidden or not always Zeta library return Hidden = true this is wrong case because the file does not exist it must return exception like System.IO.File.GetAttributes(_Path).
Example:
bool isHidden = ((ZetaLongPaths.ZlpIOHelper.GetFileAttributes(txtPath.Text) & ZetaLongPaths.Native.FileAttributes.Hidden) == ZetaLongPaths.Native.FileAttributes.Hidden); >>>>>>> always return True for not exist file.
bool isHidden = ((System.IO.File.GetAttributes(txtPath.Text) & System.IO.FileAttributes.Hidden) == System.IO.FileAttributes.Hidden); >>>>>>> return exception.
I need help to make ZetaLongPaths.ZlpIOHelper.GetFileAttributes return the same result of System.IO.File.GetAttributes.
I am looking for the file type description.
Where is that? if no, is it going to be added in a short future?
First of all, thank you for all your hard work you have put in in making this project.
Getting Error Code 0 when reading a files information eg owner and so on.
I'm thinking it might have something to do with getting these file properties if the file is currently in use?
I have however made a work around by streaming the file first and if it can stream, then that means the file is not locked, however if it cant, it means the file is locked and in use.
Seems to have solved my issue, well for now, however I was wondering if Error 0 is possibly something else?
Hello,
I am experiencing an issue with Zeta Long Paths.
When I want to get the files within a directory which contains the char ~, the name of files it contains starts with "\\?\C:" instead of "C:" only.
Here is my code:
Dim path as String = "C:\path~test"
Dim objFileInfo As ZlpFileInfo
Dim objDir As ZlpDirectoryInfo = New ZlpDirectoryInfo(path)
For Each objFileInfo In objDir.GetFiles()
MsgBox(objFileInfo.FullName) ' \\?\C:\path~test\my_file
Next
I don't have the issue when I use the correct file path to create a ZlpFileInfo object:
MsgBox(New ZlpFileInfo(path + "\my_file").FullName) 'C:\path~test\my_file
any idea to work on watcher events when using zeta such as:
watcher.Deleted += new System.IO.FileSystemEventHandler(OnDeleted);
watcher.Renamed += new System.IO.RenamedEventHandler(OnRenamed);
private void OnRenamed(object source, System.IO.RenamedEventArgs e)
{
try
{
FileSystemEvent fse;
if (ZlpIOHelper.FileExists(e.FullPath))
{
fse = new FileSystemEvent(e.OldFullPath, e.FullPath, FileSystemType.FILE);
}
else if (ZlpIOHelper.DirectoryExists(e.FullPath))
{
fse = new FileSystemEvent(e.OldFullPath, e.FullPath, FileSystemType.FOLDER);
}
else
{
fse = new FileSystemEvent(e.OldFullPath, e.FullPath, FileSystemType.UNKNOWN);
}
FileSystemEventDispatcher.Instance.Enqueue(fse);
}
catch (Exception ex)
{
}
}
e.OldFullPath when using a long path returns too long an exception.
Hi, Thanks for this great work.
This library has not ZlpFileInfo.OpenRead
method.
public System.IO.FileStream OpenRead()
{
return new System.IO.FileStream(
ZlpIOHelper.CreateFileHandle(
_path,
CreationDisposition.OpenAlways,
FileAccess.GenericRead,
FileShare.Read),
System.IO.FileAccess.Read);
}
Hi,
I'm trying to use 'ZlpIOHelper.CreateDirectory' on a path with a share name, for example:
"\192.168.11.150\Share\data"
the long path representation is:
"?\UNC\192.168.11.150\Share\data"
When I try o run create directory on this, Zlp doesn't detect that this is a share path: SplitFolderPath removes the '?\UNC" prefix, which leaves '192.168.11.150\Share\data...", and this is a normal path. As a result I get a directory in the working dir of my application, rooted at '192.168.11.150'.
I'm using ZetaLongPaths 1.0.0.6.
Hi, ZlpDirectoryInfo.CreateSubdirectory
method is missing.
It can be implemented this way:
public ZlpDirectoryInfo CreateSubdirectory(string name)
{
var path = ZlpPathHelper.Combine(_path, name);
ZlpIOHelper.CreateDirectory(path);
return new ZlpDirectoryInfo(path);
}
We have a process that checks whether a file exists or not and does something based on this check. The ZlpFileInfo inaccurately states the file exists when it does not:
\\{LONG_NETWORK_PATH\~$HIDDEN_EXCEL_FILE_LOCK.xlsm
For example:
\\xyz.com\dfsroot-us\shared\G\PMOutput\Mont\F\~$F_vPrd.xlsm
I have a .NET standard library referencing ZetaLongPaths.NetStandard. This library is then referenced by a .NET full framework library. The .NET full framework library is referencing ZetaLongPaths .NET full framework version. When the .NET full framework library runs, I get the following error:
Could not load file or assembly 'ZetaLongPaths, Version=1.0.0.14, Culture=neutral, PublicKeyToken=b764f59068f31f38' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
This seems to be a conflict between the two libraries. Is this expected?
Apparently, ZlpFileInfo makes use of System.IO to return file Length, throwing the very exception it is supposed to avoid.
The error could be reproduced with a code similar to:
string path = "C:\\Users\\cliente\\Desktop\\DRIVES~2\\mdzip\\PASTAC~1\\SUBPAS~1\\PASTAC~1\\SUBPAS~1\\SUBDAS~1\\bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.txt";
var info = new ZlpFileInfo(path);
info.Length...
The exception traceback were as follows:
System.IO.PathTooLongException: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
at System.IO.PathHelper.Append(Char value)
at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
at System.IO.Path.GetFullPathInternal(String path)
at System.IO.FileInfo.Init(String fileName, Boolean checkHost)
at System.IO.FileInfo..ctor(String fileName)
at ZetaLongPaths.ZlpIOHelper.GetFileLength(String filePath) in c:\P\ZetaLongPaths\Source\Runtime\ZlpIOHelper.cs:line 1277
at ZetaLongPaths.ZlpFileInfo.get_Length() in c:\P\ZetaLongPaths\Source\Runtime\ZlpFileInfo.cs:line 171
at DriveShare.Drive.FileDownloader.DownloadIscomplete(DriveFile driveFile, String targetPath) in c:\projetos\driveshareclient\DriveShare\DriveShare\Drive\FileDownloader.cs:line 49
at DriveShare.Drive.FileDownloader.DownloadFile(IndexedFile file, String targetPath) in c:\projetos\driveshareclient\DriveShare\DriveShare\Drive\FileDownloader.cs:line 35
at DriveShare.Drive.Storage.DownloadFile(IndexedFile file, String targetPath) in c:\projetos\driveshareclient\DriveShare\DriveShare\Drive\Storage.cs:line 40
at DriveShare.Tasks.DownloadTask.Execute() in c:\projetos\driveshareclient\DriveShare\DriveShare\Tasks\DownloadTask.cs:line 20
at DriveShare.Workers.TaskWorker.ExecuteTask(Task task) in c:\projetos\driveshareclient\DriveShare\DriveShare\Workers\TaskWorker.cs:line 64
at DriveShare.Workers.TaskWorker.TryExecuteTask(Task task) in c:\projetos\driveshareclient\DriveShare\DriveShare\Workers\TaskWorker.cs:line 35
Hi,
Is this software licensed under an FLOSS/Open Source license? Would it, in that case, be possible to include a LICENSE file in the root of the repository?
The project seems really great, but using software without a stated license is way too dangerous for me.
Victor Blomberg
Hi, With new version 1.0.0.15 I had a big problem during move file example error File: \CEDXXX\XXXX\1163286\4112.pdf non è stato elaborato, causa Error 17 moving file '\CEDXXX\XXXX\1163286\4112.pdf' to '\CEDYYY\BARTBACKUP\VASYYY\20160324_01\1163286\4112.pdf': The system cannot move the file to a different disk drive.
with previous version the command execution didn't error (1.0.0.14).
Now I must rollback previus version.
If you try to move an entire SubDirectory one ore more levels up inside the same Directory, you get an error like
"can't be moved if directory already exists..."
Example:
SourceDir = C:\temp\SourceDir\SubDir1\SubDir2\SubDir3 (with various files.xxx inside)
TargetDir = C:\temp\SourceDir
Attempt to move the \SubDir3 (with entire content) to \SourceDir
ZetaLongPaths.ZlpIOHelper.MoveDirectory(SourceDir , TargetDir)
Why should it not be possibe to .MoveDirectory
inside the same directory structure?
Hi,
I can see in our logs that we get many logs from your library. It is good to have logs on critical moments but all logs like "About to do ..." are a bit overhead from user perspective. Could those be removed? There are few methods that have that log at the beginning.
I have a question about FolderBrowserDialog
and OpenFileDialog
when selecting a file or folder in a long path if you know any method to use it in the long path or if the Zeta Library contains any such type of these?
Will this library run on Mono too or do I need to distribute a separate version of my application that simply uses the default IO libs for that?
The GetFileNameWithoutExtension method works a bit different that the System.IO.Path one.
For path @"C:\Directory\File" the method returns an empty string while the System.IO.Path one returns "File".
The latest package has a Dependency to JetBrains.Annotations 1.0.0
which leads to a compiler warning:
warning NU1603: ZetaLongPaths 1.0.9.41 depends on JetBrains.Annotations (>= 1.0.0) but JetBrains.Annotations 1.0.0 was not found. An approximate best match of JetBrains.Annotations 6.1.0 was resolved.
...
<dependencies>
<dependency id="JetBrains.Annotations" version="1.0.0" />
</dependencies>
...
On https://www.nuget.org/packages/JetBrains.Annotations there is no matching version. Can you please remove this dependency since it is not required as a runtime dependency?
Why the ZetaLongPath fileStream = new ZetaLongPaths.ZlpFileInfo(sVolumePath).OpenRead();
return Error 5 creating file handle for file path “\?\C:\HOTLongPathTEST\TestLongPathhhhhhh211\Newfolder11\Maaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaain11\Roooooooooooooooooooooooooooooooooooooooooooooooot11\ALLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL11\QAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrrrrrtttttttttttttttttttttttttttttttttttt11\originallllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll11\testttt\test\tttt (2).txt”: Access is denied.
as a general exception not as UnauthorizedAccessException how to solve it?!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.