I need to zip files from folder X to folder Y. When the files from folder X are zipped into folder Y. The files in folder X needs to be removed. The zip name must be the name of the file with the .DBS in that folder.
So I need to read whats the file name of the .DBS file is. Then I need to zip all the files in folder X to folder Y with the name: "Filename" (this is the same as the .DBS file) If the files are zipped and well in folder Y they need to be removed from folder X.
The code that I got at the moment will move the files of folder X too Y. So this is a start. My question is how can I get the name of the file too be the zip folder name.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.IO.Compression;
namespace Ramasoftzipper
{
class Program
{
static void Main(string[] args)
{
string fileName = @"160001.DBS";
string sourcePath = @"C:\RMExport";
string targetPath = @"C:\Exportrm";
string sourceFile = System.IO.Path.Combine(sourcePath, fileName);
string destFile = System.IO.Path.Combine(targetPath, fileName);
string startPath = @"C:\RMExport";
string zipPath = (fileName);
string extractPath = @"C:\Exportrm";
if (!System.IO.Directory.Exists(targetPath))
{
System.IO.Directory.CreateDirectory(targetPath);
}
System.IO.File.Copy(sourceFile, destFile, true);
if (System.IO.Directory.Exists(sourcePath))
{
string[] files = System.IO.Directory.GetFiles(sourcePath);
foreach (string s in files)
{
fileName = System.IO.Path.GetFileName(s);
destFile = System.IO.Path.Combine(targetPath, fileName);
System.IO.File.Copy(s, destFile, true);
ZipFile.CreateFromDirectory(startPath, zipPath);
ZipFile.ExtractToDirectory(zipPath, extractPath);
}
}
else
{
Console.WriteLine("Source path does not exist!");
}
}
}
}
Thanks in advance.
string[] files = System.IO.Directory.GetFiles(path, "*.DBS");this will retrieve all the filenames that have a .DBS extension. Is that what you need ?