Skip to content

About

Get the date and time of the last edit by default (`/D` is optional), the date created with `/C` flag, or get both with `/B` flag of files and folders. **Built with TypeScript** - Includes full type definitions for use in TypeScript projects.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

logo

Get the date and time of the last edit by default (/D is optional), the date created with /C flag, or get both with /B flag of files and folders.

Built with TypeScript - Includes full type definitions for use in TypeScript projects.

Installation

npm install -g getfiledate

Or clone and install locally:

git clone https://github.com/jhauga/getFileDate.git
cd getFileDate
npm install
npm run build
npm link

Usage

getFileDate [flags] [options] [files...]

Flags

Flags control which date type to display:

  • /B - Output both date of last edit and date created
  • /C - Output only the date created
  • /D - Output the last edit date (default)

Note: Flags are case-insensitive (/b, /c, /d also work)

Options

  • -d, --date [files...] - Get only the date
  • -t, --time [files...] - Get only the time
  • -h, --help - Show help message
  • --version - Show version number

Option Parameters

Some options support additional parameters:

  • --date:slash - Use slash (/) as date separator instead of dash (-)
  • --date:dash - Use dash (-) as date separator (default)

Combining Options

Short options can be combined for convenience:

-dt          # Get date and time

Important: When combining options, only the last option can have a parameter.

Valid Examples

-dt file.txt               # Get date and time
-d:slash file.txt          # Get date with slash separator

Examples

Basic Usage

List all files and folders in current directory with last edit date and time:

getFileDate

Output:

03-03-2026   01:57 PM   .
03-03-2026   01:37 PM   ..
03-03-2026   01:57 PM   .github
03-03-2026   01:57 PM   getFileDate.code-workspace
03-03-2026   01:57 PM   task.bat

Using Flags

Show created date only:

getFileDate /C

Output:

03-03-2026   02:57 AM   .
03-03-2026   02:37 AM   ..
03-03-2026   02:57 AM   .github
03-03-2026   02:57 AM   getFileDate.code-workspace

Show both created and last edit dates:

getFileDate /B

Output:

[created]   03-03-2026   01:57 PM   .
[last edit] 03-03-2026   02:57 AM   .
[created]   03-03-2026   01:37 PM   ..
[last edit] 03-03-2026   02:37 AM   ..
[created]   03-03-2026   01:57 PM   .github
[last edit] 03-03-2026   02:57 AM   .github

Using Options

Get only the date:

getFileDate --date

Output:

03-03-2026   .
03-03-2026   ..
03-03-2026   .github

Get only the time:

getFileDate --time

Output:

01:57 PM   .
01:37 PM   ..
01:57 PM   .github

Single File Output

When specifying a single file, the filename is not shown in output:

getFileDate -d file.txt

Output:

03-03-2026
getFileDate -t file.txt

Output:

01:57 PM

Date Separator Options

Use slash separator instead of dash:

getFileDate --date:slash file.txt

Output:

03/03/2026

Multiple Files

Specify multiple files separated by commas:

getFileDate -d fileA.txt,fileB.txt,fileC.txt

Output:

03-03-2026   fileA.txt
03-03-2026   fileB.txt
03-03-2026   fileC.txt

Complex Examples

Combine flags and options:

getFileDate /C -t fileA.txt -d fileB.txt /D fileC.txt

Output:

01:57 AM   fileA.txt
03-03-2026 fileB.txt
01:57 PM   fileC.txt

API Usage

You can also use getFileDate as a library in your Node.js or TypeScript projects:

JavaScript

const { getFileDates, formatDate, formatTime, formatBoth } = require('getfiledate');

async function example() {
  // Get file dates
  const dates = await getFileDates('./myfile.txt');
  console.log('Created:', dates.created);
  console.log('Modified:', dates.modified);

  // Format dates
  const formattedDate = formatDate(dates.modified, '-');
  console.log('Date:', formattedDate); // e.g., "03-03-2026"

  const formattedTime = formatTime(dates.modified);
  console.log('Time:', formattedTime); // e.g., "01:57 PM"

  const formattedBoth = formatBoth(dates.modified, '-');
  console.log('Both:', formattedBoth); // e.g., "03-03-2026   01:57 PM"
}

example();

TypeScript

import { getFileDates, formatDate, formatTime, formatBoth, FileDates } from 'getfiledate';

async function example(): Promise<void> {
  // Get file dates - fully typed!
  const dates: FileDates = await getFileDates('./myfile.txt');
  console.log('Created:', dates.created);
  console.log('Modified:', dates.modified);

  // Format dates with type-safe parameters
  const formattedDate: string = formatDate(dates.modified, '-');
  console.log('Date:', formattedDate); // e.g., "03-03-2026"

  const formattedTime: string = formatTime(dates.modified);
  console.log('Time:', formattedTime); // e.g., "01:57 PM"

  const formattedBoth: string = formatBoth(dates.modified, '/');
  console.log('Both:', formattedBoth); // e.g., "03/03/2026   01:57 PM"
}

example();

Available Types

interface FileDates {
  created: Date;
  modified: Date;
}

function getFileDates(filePath: string): Promise<FileDates>;
function formatDate(date: Date, separator?: string): string;
function formatTime(date: Date): string;
function formatBoth(date: Date, separator?: string): string;
function padString(str: string, width: number): string;

Development

Building from Source

npm run build        # Build the project
npm run watch        # Build and watch for changes
npm run clean        # Clean build artifacts

Running Tests

npm test

Project Structure

getFileDate/
├── src/
│   ├── bin/
│   │   └── getFileDate.ts      # CLI executable (TypeScript)
│   └── lib/
│       ├── index.ts            # Core date/time functions (TypeScript)
│       └── argParser.ts        # Argument parsing logic (TypeScript)
├── test/
│   └── test.ts                 # Test suite (TypeScript)
├── dist/                       # Compiled JavaScript output
├── tsconfig.json               # TypeScript configuration
├── .gitignore
├── LICENSE
├── package.json
└── README.md

Requirements

  • Node.js >= 14.0.0
  • TypeScript >= 5.0.0 (for development only)

License

MIT License - see LICENSE file for details

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

About

Get the date and time of the last edit by default (`/D` is optional), the date created with `/C` flag, or get both with `/B` flag of files and folders. **Built with TypeScript** - Includes full type definitions for use in TypeScript projects.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages