• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Regarding absolute path

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Folks,
I have one query is that I have developed a program that ask from user to enter the drive( c: d:) and the folder name and based on these parameters it calculates the lines of code in that folder of all the files inside that folder but now the problem is lets say one user has kept the folder in C:\Test\ and other user has kept the folder in C:\abc\Test\ so nesting could happen , so to solve this issue ,I was thinking of the logic that to take full absolute path from the user itself , and based on that absolute path my current program will work , please advise how to achieve this, my present logic is



Please advise how to add the logic of taking the full absolute path from the user and then working on that absolute path
One more thing is that I was thinking is that from the user will enter the complete path lets say c:/abc/def/Test and that we will accept it as string and based on that we will continue with our existing logic , please advise
 
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, the location of the files is not something you can control or influence in your application so it makes sense to make the user provide all of it.
Some people could be running on unix environments as well.
 
naresh saxena
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

E Armitage wrote:Yes, the location of the files is not something you can control or influence in your application so it makes sense to make the user provide all of it.
Some people could be running on unix environments as well.



I am talking of windows requirement only ,One more thing is that I was thinking is that from the user will enter the complete path lets say c:/abc/def/Test and that we will accept it as string and based on that we will continue with our existing logic , please advise
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

naresh saxena wrote:

E Armitage wrote:Yes, the location of the files is not something you can control or influence in your application so it makes sense to make the user provide all of it.
Some people could be running on unix environments as well.



One more thing is that I was thinking is that from the user will enter the complete path lets say c:/abc/def/Test and that we will accept it as string and based on that we will continue with our existing logic , please advise


Sounds viable. You have to worry about the validity of the entered path though because some users will enter an invalid path.
Another option is to add gui capabilities to the program and use a JFileChooser instead.
 
naresh saxena
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

E Armitage wrote:
Sounds viable. You have to worry about the validity of the entered path though because some users will enter an invalid path.
Another option is to add gui capabilities to the program and use a JFileChooser instead.



Thanks could you please show me how to use jfilechooser as when I am browsing to the particular folder , I want to select the folder only and all the files in that folder to be get selected and the logic of displaying the file name along with Counting lines of code would be the same one as I have shown, Please advise
 
E Armitage
Rancher
Posts: 989
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You tell the chooser to select directories only using

See more details here:http://docs.oracle.com/javase/tutorial/uiswing/components/filechooser.html

 
naresh saxena
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

E Armitage wrote:You tell the chooser to select directories only using

See more details here:http://docs.oracle.com/javase/tutorial/uiswing/components/filechooser.html



Thanks, I have come up with this below piece of code .. first please advise where the changes need to be done so that user click on directory test and it will accept the directory



This is my UI but i want to integrate my first piece of code to count the number of lines in all the file , please advise how to do that
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use a structure like:


Your actionPerformed logic should ideally run in its own thread as well if it is to do with IO over an indefinite number and size of files.
 
naresh saxena
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Folks,
I have come up with the solution but it is selecting only file , my code is..

but it is selecting only single file
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use chooser.getSelectedFile(); instead of chooser.getCurrentDirectory();
 
naresh saxena
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

E Armitage wrote:Use chooser.getSelectedFile(); instead of chooser.getCurrentDirectory();



come up with solution that is working..Here below is the piece of code..

 
E Armitage
Rancher
Posts: 989
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't need to do

choosers.getSelectedFile() already returns a File so just assign that rather than creating another file object

 
naresh saxena
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

E Armitage wrote:You don't need to do

choosers.getSelectedFile() already returns a File so just assign that rather than creating another file object



Thanks Armitage , could you also please advise let say I want initially upon executing the application a main window should come with two button ENTER and EXIT , upon clicking the EXIT the application should end's up and upon clicking on ENTER the my application will open the dialog to select the folder as it is doing presently. what the main objective an main window with two buttons should com up first , please advise how to achiev that and integrate with the present application
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See the example structure code (including comments) I posted above.
But what you really need to learn is how to use a layout manager for your swing components. In this case you could use a CardLayout. The excellent tutorial for it is here: http://docs.oracle.com/javase/tutorial/uiswing/layout/card.html
 
naresh saxena
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

E Armitage wrote:



Thanks a lot it works , could you also please advise when I execute this application , it is by default when dialog box get opened it is in some other folder location by default , I want that upon execution it is by default in c: location , further user can navigate ,please advise how to achieve this, Thanks in advance.
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See the API specs for the JFileChooser constructor that takes a String. Careful that you don't resurrect the problem of coding to a specific platform. Remember that some users won't have a C:\\
You could try fiddling with things like File.listRoots to be sure but I'd think that most users would prefer the default to point to their own default documents folder than to the system's root folder.
 
naresh saxena
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

E Armitage wrote:See the API specs for the JFileChooser constructor that takes a String. Careful that you don't resurrect the problem of coding to a specific platform. Remember that some users won't have a C:\\
You could try fiddling with things like File.listRoots to be sure but I'd think that most users would prefer the default to point to their own default documents folder than to the system's root folder.



Thanks Achieve that through ...
 
There is no greater crime than stealing somebody's best friend. I miss you tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic