getfiledate
v1.0.0
Published
Get the date and time of the last edit or date created of files and folders
Maintainers
Readme
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 getfiledateOr clone and install locally:
git clone https://github.com/jhauga/getFileDate.git
cd getFileDate
npm install
npm run build
npm linkUsage
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 timeImportant: 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 separatorExamples
Basic Usage
List all files and folders in current directory with last edit date and time:
getFileDateOutput:
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.batUsing Flags
Show created date only:
getFileDate /COutput:
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-workspaceShow both created and last edit dates:
getFileDate /BOutput:
[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 .githubUsing Options
Get only the date:
getFileDate --dateOutput:
03-03-2026 .
03-03-2026 ..
03-03-2026 .githubGet only the time:
getFileDate --timeOutput:
01:57 PM .
01:37 PM ..
01:57 PM .githubSingle File Output
When specifying a single file, the filename is not shown in output:
getFileDate -d file.txtOutput:
03-03-2026getFileDate -t file.txtOutput:
01:57 PMDate Separator Options
Use slash separator instead of dash:
getFileDate --date:slash file.txtOutput:
03/03/2026Multiple Files
Specify multiple files separated by commas:
getFileDate -d fileA.txt,fileB.txt,fileC.txtOutput:
03-03-2026 fileA.txt
03-03-2026 fileB.txt
03-03-2026 fileC.txtComplex Examples
Combine flags and options:
getFileDate /C -t fileA.txt -d fileB.txt /D fileC.txtOutput:
01:57 AM fileA.txt
03-03-2026 fileB.txt
01:57 PM fileC.txtAPI 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 artifactsRunning Tests
npm testProject 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.mdRequirements
- 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.

