Username:   Password:  

Bash script to append a .txt extension to a filename

for i in *.log*; do mv "$i" "$i.txt"; done
 

Iterate over the current directory, get all files with .log and append .txt to the end of the entire filename:

Tags

bash files iterate filename

Count lines of a file

/// <summary>
/// Counts the lines of a File.
/// </summary>
/// <param name="fileToCount">The file to count.</param>
/// <returns>lines of a File</returns>
private static int CountLines(string fileToCount)
{
    int counter = 0;
    using (StreamReader countReader = new StreamReader(fileToCount))
    {
        while (countReader.ReadLine() != null)
            counter++;
    }
    return counter;
}
 

Tags

C# CSharp .NET count lines files

Test filename in PHP

/**
 * Tests, if given filename is valid
 *
 * @param string $filename
 * @return bool
 */
public static function isValidFilename($filename) {
	return (bool) preg_match('/^[a-z0-9_ ]{1,30}.[a-z]{1,3}$/i', $filename);
}

Tests, if a given filename is valid.

Tags

PHP files filename test verify

List all text files and append foo

for i in *.txt; do echo $i"foo"; done
 

Lists all files and appends "foo" to every file (only on the output).

Tags

list files bash

Read File Permissions in C#

String fullPath = Path.GetFullPathInternal(path);
// For security check, path should be resolved to an absolute path.
new System.Security.Permissions.FileIOPermission(FileIOPermissionAccess.Write, new String[] { fullPath }, false, false ).Demand(); 

Tags

permissions files c#