Questions tagged [fileinfo]

fileinfo refers to the properties of a file that are not part of the content, but rather meta-information such as file type, last modification time, id in the file system, etc. Use this tag for questions about reading / modifying the fileinfo in programmatic ways.

Fileinfo refers to the properties of a file that are not part of the content, but rather meta-information such as file type, last modification time, id in the file system, etc. It can include custom properties such as ID3 tags for audio files.

The list of attributes may vary depending on the file system.

Use this tag for questions about reading / modifying the fileinfo in programmatic ways.

361 questions
121
votes
8 answers

How to check if a file exists in a folder?

I need to check if an xml file exists in the folder. DirectoryInfo di = new DirectoryInfo(ProcessingDirectory); FileInfo[] TXTFiles = di.GetFiles("*.xml"); if (TXTFiles.Length == 0) { log.Info("no files present") } Is this the best way to check…
user386258
  • 1,933
  • 8
  • 22
  • 28
104
votes
7 answers

GetFiles with multiple extensions

Possible Duplicate: Can you call Directory.GetFiles() with multiple filters? How do you filter on more than one extension? I've tried: FileInfo[] Files = dinfo.GetFiles("*.jpg;*.tiff;*.bmp"); FileInfo[] Files =…
rd42
  • 3,584
  • 15
  • 56
  • 68
67
votes
7 answers

Get all files and directories in specific path fast

I am creating a backup application where c# scans a directory. Before I use to have something like this in order to get all the files and subfiles in a directory: DirectoryInfo di = new DirectoryInfo("A:\\"); var directories= di.GetFiles("*",…
Tono Nam
  • 34,064
  • 78
  • 298
  • 470
32
votes
7 answers

Can I show file copy progress using FileInfo.CopyTo() in .NET?

I've created a copy utility in c# (.NET 2.0 Framework) that copies files, directories and recursive sub directories etc. The program has a GUI that shows the current file being copied, the current file number (sequence), the total number of files to…
Jason Down
  • 21,731
  • 12
  • 83
  • 117
29
votes
4 answers

Does FileInfo.Extension return the last *.* pattern, or something else?

I'm curious what exactly the behavior is on the following: FileInfo info = new FileInfo("C:/testfile.txt.gz"); string ext = info.Extension; Will this return ".txt.gz" or ".gz"? What is the behavior with even more extensions, such as ".txt.gz.zip"…
Codeman
  • 12,157
  • 10
  • 53
  • 91
27
votes
7 answers

.NET FileInfo.LastWriteTime & FileInfo.LastAccessTime are wrong

When I call FileInfo(path).LastAccessTime or FileInfo(path).LastWriteTime on a file that is in the process of being written it returns the time that the file was created, not the last time it was written to (ie. now). Is there a way to get this…
Mr. Flibble
  • 26,564
  • 23
  • 69
  • 100
23
votes
2 answers

c# replace string within file

String.Replace doesn't seem to work properly when replacing a portion of an HTML file's content. For example, String.Replace replaces with blah blah blah html> - notice the second HTML closing tag is not properly…
Joey
  • 231
  • 1
  • 2
  • 3
18
votes
3 answers

Finfo_file on uploaded file to determine mime-type

Im trying to determine the mime-type of an uploaded file, i want to use fileinfo(), this is what ive been trying, it isnt working: $uploadedfile = $_FILES['soup']['tmp_name']; if(isset($uploadedfile)) { $uploadedname = $_FILES['soup']['name']; …
JimmyBanks
  • 4,178
  • 8
  • 45
  • 72
17
votes
7 answers

File.Delete() versus FileInfo.Delete()

Is there much of a difference between using the static methods of the File object as opposed to creating a new FileInfo object and calling those methods?
Tim Coker
  • 6,484
  • 2
  • 31
  • 62
17
votes
2 answers

SPLFileInfo: get filename without extension

I'm accessing a number of files in the SPLFileInfo object. I see a way to get the path, filename, and even extension of the file. Is there a way to get the filename without extension? Here's the code I've been working with but I'm hoping to get…
tzvi
  • 471
  • 3
  • 5
  • 19
14
votes
3 answers

Python program to traverse directories and read file information

I'm just getting started with Python but already have found it much more productive than Bash shell scripting. I'm trying to write a Python script that will traverse every directory that branches from the directory I launch the script in, and for…
dvanaria
  • 6,593
  • 22
  • 62
  • 82
14
votes
6 answers

Get file size without using System.IO.FileInfo?

Is it possible to get the size of a file in C# without using System.IO.FileInfo at all? I know that you can get other things like Name and Extension by using Path.GetFileName(yourFilePath) and Path.GetExtension(yourFilePath) respectively, but…
sergeidave
  • 662
  • 4
  • 11
  • 23
12
votes
10 answers

When passing a file name to a method, should I use FileInfo or a plain file name?

Well, the title says it all. When passing a file name to a method, should I use a FileInfo object or a plain file name (string)? Why would I prefer one to the other? Some of my colleagues like to write method like this: void Export(FileInfo…
Martin
  • 39,309
  • 62
  • 192
  • 278
12
votes
3 answers

Using php_fileinfo.dll and finfo_open in Windows PHP 5.3.5

I'm having trouble calling finfo_open in a PHP script running on Windows Server 2003 with PHP 5.3.5 & IIS 6. The call always returns Fatal error: Call to undefined function finfo_open() in... Through a little reading I know that fileinfo…
tomfumb
  • 3,669
  • 3
  • 34
  • 50
12
votes
5 answers

DirectoryInfo, FileInfo and very long path

I try to work with DirectoryInfo, FileInfo with very long path. I try use \\?\c:\long path (i got illegal caracter with fileInfo and DirectoryInfo) I try use file://c:/long path (i got uri not supported) Can i use ~ in a path or something else. I…
Cédric Boivin
  • 10,854
  • 13
  • 57
  • 98
1
2 3
24 25