Created
July 20, 2024 18:01
-
-
Save ishar19/508709604e22290ca3e4def2b77adb39 to your computer and use it in GitHub Desktop.
absolute to relative
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const path = require('path'); | |
| const exec = require('child_process').exec; | |
| function absoluteToRelative(absolutePath) { | |
| // Normalize the paths to remove any unnecessary separators | |
| // const normalizedAbsolutePath = path.normalize(absolutePath); | |
| const currentPath = path.normalize(process.cwd()); | |
| const relativePath = path.relative(currentPath, absolutePath); | |
| return relativePath; | |
| } | |
| // Example usage | |
| const absolutePath = '/Users/ishar/Downloads/ffmpeg-exp/folder/index.js'; | |
| const relativePath = absoluteToRelative(absolutePath); | |
| console.log(relativePath); // Output: src/components/Button.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment