Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9294467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T21:22:47+00:00 2026-06-18T21:22:47+00:00

I am accepting a path to a directory as a command line argument to

  • 0

I am accepting a path to a directory as a command line argument to one of my scripts. There are two things I want to do. The first is that I want to confirm that path passed in a directory. The second thing I want to do is append to the path with sub-directory names (I know the sub-directory names ahead of time). Are there any functions in the library that will automatically add a trailing / character to the path if it is missing, or must I check for this manually?

For instance, if /User/local is passed, then I must add /bin to the path, whereas I must add bin if the path /User/local/ is passed.

Thanks for the help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T21:22:49+00:00Added an answer on June 18, 2026 at 9:22 pm

    It seems like you just want path.join, fs.existsSync, and fs.statSync

    var path = require('path');
    var fs = require('fs');
    
    var dir = process.argv[2];
    
    console.log(dir);
    console.log(fs.existsSync(dir) && fs.statSync(dir).isDirectory());
    console.log(path.join(dir, 'mysubdir'));
    

    So if I run the above like: node test.js /tmp I will get:

    /tmp
    true
    /tmp/mysubdir
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a function in C# that gets a directory path as
I have a products.jar file. Inside that there is one class com.ClassA . The
I'm accepting dates from a wicket form - now I want query my DAO
I want a regular expression for only accepting 0-9999 No spaces, no letters. However,
I wrote a command line utility using Zend Framework to do some nightly reporting.
I have two programs which are accessing a directory using the .NET Directory class
I know the solid security recommendation of avoiding accepting user input that you then
In VB.net when loading in XML documents using System.Xml.Xmldocument is there a way that
How do I make a custom action that references a file on the command
How to use a relative path to read the content of a directory kept

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.