get file names of files

  • Thread starter Thread starter HateBSOD
  • Start date Start date
H

HateBSOD

Say I want to get the file name of C:\temp\something.xml and have that
put into a variable so I can encrypt the file and output it to
c:\temp\filename.enc. I have not found anything that solves this for
me.

I tired this

static void Main(string[] args)
{
string fileName = @("C:\","*.xml");
string path = @"C:\*.xml";
string result;

result = Path.GetFileName(fileName);
but that has to be static. Any help is appreciated.
 
Not sure I understand your problem. What happens when you run your example
below? What do you mean by "but that has to be static"?
 
HateBSOD,

The static GetFileName method on the Path class doesn't find files given
a wildcard string. Rather, it takes the file part of the path, and returns
that.

If you want to find files, I don't believe there is a managed code
method you can use. However, you can call the FindFirstFileEx function
through the P/Invoke layer.

Once you find your files, you can use the classes in the
System.Security.Cryptography namespace to encrypt the file, and the classes
in the System.IO namespace (specifically the FileStream class) to write the
new file.

Hope this helps.
 
hi
it is hard to get what you mean by " that has to be static " . would you
explain more what is the problem
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
 
I figured out that mess ended up being Directory.GetFiles to work, but
on the other hand I am using DES encryption and it works fine with
text, but not with a binary.

Do these have to use the binary writer or are these just for the keys,
anyways anyone have any ideas or samples on how to encrypt binary
files, with DES or AES.

DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey);

Thanks.
 
Back
Top