I need to unzip (N) files from a local directory. I am using .NET 4.5 and the using System.IO.Compression.ZipFile.ExtractToDirectory for extraction. My problem is this renames the files upon extraction. Example both of these files will extract to Scouting_20160603 directory. So when I get to the second extraction there are name collisions.
cheers
bob
WPFPotatoScouting_20160603.zip
WPFRotationScouting_20160603.zip
Turned out inside each file was a directory named Scouting_20160603. Why it unzipped to that name and not the file name is still puzzling me. But I have this answer.
Related
I Ran FileInfo.MoveTo("filename.txt") with just a name instead of passing a full path and the file just disappeared. I believe in linux this would make it go to the root directory "/", but on Windows I'm not sure if there is a such thing as a root directory beyond just C: Is there any way to locate my lost file?
It is likely in the working folder that your executable is running from. For example, MyApp\bin\Debug, depending on the configuration you are running in.
It should be in project folder. Usually files without specefying path are saved there. (in folder with .exe file)
I have an application to unzip .Zip, .rar and .7zip files.
However I am faced with a problem, when a mac user sends a zip with files whose names contain for example ":" this crashes my application which is quite normal because Windows does not accept this kind of element in the name of a file.
In short, Apple ...
After some tests, I realized that we could change the name of the files in the archive using Winrar.
So do you have any idea how I can change the name of the files in the archive before extracting it (in C#) ?
I tried ZipArchive but it crashes because it is intended for Windows so quite normal.
Thank's in advance ;)
I'm trying to find a file in a settings folder in my application. I have a xml file there. When I run the following code:
XDocument xDoc = XDocument.Load(#"..\settings\Settings.xml");
I get the DirectoryNotFoundException and the exception says not found at \bin\settings\Settings.xml'., instead of above. I even tried the full root directory to see the issue, C://... but it still includes a bin folder?
How can I have it so it doesn't include the bin part?
By default, the build results in Visual Studio are saved in a folder like bin\Debug. Since you use a relative path that jumps one folder higher, you get yourProjectFolder\bin\settings\Settings.xml. That file doesn't exist, since it's presumably in the project folder, not the bin folder.
The typical way to deal with this is to make sure the files that are supposed to be a part of the content actually have Build Action set to Content.
Using a rooted path definitely works - most likely, you made a mistake somewhere; either the path isn't rooted at all, or you're doing something like interpreting the path as an URI rather than a file path. XDocument.Load takes a URI, not a file path - the proper way to reference an absolute path on the filesystem would be file://C:/ThePath/Settings/Settings.xml.
I am trying to figure out how to copy the most recent file in a server directory to a local directory in c#.
I am needing to do this to over 100 directories. They will all copy and rename to the same local directory.
The directories all named: e.g. \ServerPath\01, \ServerPath\02, \ServerPath\03, etc.
Right now I have a batch script that will do it but it takes forever since it goes through each and every file in each directory.
My immediate thought was "Is this possible with Robocopy??" I did a quick search on Google for "Robocopy most recent file" and came up with a blog post about handling this with a powershell script.
This should at least provide you the latest files without you having to go through "...each and every file in each directory".
I am working with Directory.GetFiles in C#. This code is turned into an assembly which is then used in a T-SQL script. Here is the code line that I believe is the problem:
C# Code:
string[] filePaths = Directory.GetFiles(path, ext, SearchOption.AllDirectories);
Error (T-SQL script):
System.IO.DirectoryNotFoundException: Could not find a part of the path 'G:\Photography\Archive\SPBKF3~L'.
I'm assuming the tilde isn't a legal character to use for a folder name in Windows because the only folders that cause this error are the ones with a tilde. The files are being shared between Mac and Windows systems and I've found that file and folder names have been a problem in the past.
I'm having a difficult time understanding why the Directory.GetFiles method would even find a directory that doesn't exist. The folder displays in Windows Explorer but I cannot access the folder.
Is there something I can do to avoid these problem folders?
SPBKF3~L looks suspiciously like an 8.3 shortened filename. Are you sure this isn't happening somewhere?
~ is not an invalid character - I just tried creating a directory with the name SPBKF3~L, and I also wrote up a quick C# app to run your sample code on that directory and it worked fine.
There must be something else happening here - are you absolutely sure that the directory exists? (try copying and pasting the path into an explorer window)
Check the permissions on G:\Photography\Archive\SPBKF3~L and ensure that the user account the SQL Server instance is running under can see the folder.