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

Removing Spaces from a filename

Options
  • 20-06-2001 10:46am
    #1
    Registered Users Posts: 2,894 ✭✭✭


    I'm bcp'ing data files from a share to a SQL Database. My problem lies where there are spaces in the filename. Batch files can't handle spaces as it only takes the characters before the first space, and when it compares that to the file in the directory, it can't find it cos they dont match. Anyone know of a way to remove spaces from a filename through a batch/dos command ?


Comments

  • Closed Accounts Posts: 2,525 ✭✭✭JustHalf


    Have you tried putting them in quotes? This worked in Win95 for getting into "C:\Program Files", so it's worth a try.


  • Registered Users Posts: 2,494 ✭✭✭kayos


    Right this should work tested on NT4 SQL 7

    put the following into a command file and alter to your needs and run it from the directory
    for %%m in (*.tab) do BCP <DBName>.dbo.<TableName> in "%%m" -S<Server> -T -n
    

    Please note -T is a trusted connection is make sure your NT account has premissions or change it to -U<username> -P<password>. Also the -n is just for native format you might or mightnot need this.
    [edit]
    I forgot to say change the *.tab to what ever file extension you use.
    [/edit]
    Hope this helps.

    kayos

    When you get to hell tell them I sent you,
    you'll get a group discount...

    tribes.gameshop.ie

    [This message has been edited by kayos (edited 20-06-2001).]


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


    <font face="Verdana, Arial" size="2">Originally posted by TinCool:
    Anyone know of a way to remove spaces from a filename through a batch/dos command ?</font>
    Have you tried using the old short-name convention?

    Take the first 6 non-space characters, and append ~1 at the end. Oh - anything longer than 8 chars requires the same change

    Thus :

    "c:\program files\myLongDirName\some file.txt"

    would be referenceable as :

    c:\progra~1\mylong~1\somefi~1.txt

    jc



  • Registered Users Posts: 2,894 ✭✭✭TinCool


    Thanks for the suggestion guys, I left it out in the end. Basically, Sizechk craps out if it attempts to do a size check of a file that has spaces in it. For example.

    If you have a file called "f i l e.txt" and you run the following type of code:

    let %x = f i l e.txt
    sizechk %x

    sizechk will attempt to find a file called "f", since it doesn't exist, it craps out. Pain in the ass really


  • Registered Users Posts: 2,894 ✭✭✭TinCool


    Thanks for the suggestion guys, I left it out in the end. Basically, Sizechk craps out if it attempts to do a size check of a file that has spaces in it. For example.

    If you have a file called "f i l e.txt" and you run the following type of code:

    let %x = f i l e.txt
    sizechk %x

    sizechk will attempt to find a file called "f", since it doesn't exist, it craps out. Pain in the ass really


  • Advertisement
Advertisement