Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Console Applications and Filenames (.Net)

  • 31-05-2005 10:01am
    #1
    Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭


    'Lo,

    I'm passing filenames into a console application and am having problems with long filenames, namely the spaces in them.

    For example if I say: foo File.txt then foo reads the file name as File.txt. If I pass in foo File Two.txt then I can loop through the args array but the filename is then FileTwo.txt which is obviously incorrect. foo "File Two.txt" works.

    Is there any way I can get the filename passed in properly without using quotes?


Comments

  • Registered Users, Registered Users 2 Posts: 15,443 ✭✭✭✭bonkey


    Using quotes is how to pass it properly ;)

    The only other way that I'm aware of is to get the shortname (old 8.3 format) for the file, and use that. Buggahed if I can remember how its done (cause you can't just assume its the first 6 valid chars followed by tilde-1) and its not really an elegant solution anyway.


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    Yeah, quotes is standard really. No harm in asking though :D


  • Registered Users, Registered Users 2 Posts: 2,781 ✭✭✭amen


    alernatively use parameters like -Lilename -Ooutputpath
    and search for -L, -O etc in the passed params bit messer though
    quotes is nicer


  • Moderators, Society & Culture Moderators Posts: 9,689 Mod ✭✭✭✭stevenmu


    Evil Phil wrote:
    'Lo,

    I'm passing filenames into a console application and am having problems with long filenames, namely the spaces in them.

    For example if I say: foo File.txt then foo reads the file name as File.txt. If I pass in foo File Two.txt then I can loop through the args array but the filename is then FileTwo.txt which is obviously incorrect. foo "File Two.txt" works.

    Is there any way I can get the filename passed in properly without using quotes?
    I'm probably missing something obvious here it looks to me like you're getting two array elements, one with "File" and the other with "Two.txt" ? Can't you just have:

    filename = args[0] + " " + args[1]

    you'd have to put in some kind of logic to check if args[0] has a file extension, if not use args[1] aswell (altough you should really have some kind of loop to go through as many args as exist untill you get to one with a file extension and add them together with the spaces). If you need to handle other args you'd want to maintain an integer which holds how many places in the array to skip.

    I don't think I've ever seen an app handle long file names properly, nice to see someone making that extra bit of effort.


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    Nah, quotes are the way its done I'm afraid. The problem with looping through the args array is you can't be sure how many spaces are being skipped. You could code around it I suppose but people expect to use quotes so I'm not going to bother.


  • Advertisement
Advertisement