0

This is a TCC code.

I wanted my .BAT file to return a shortened name for a specified file (with @ALTNAME), but I don't want it to return the whole path of the file. My solution doesn't seem to be working. Can someone tell me what am I doing wrong?

I used the function @FILENAME and added it to a variable. Then, I used @ALTNAME with the variable. Is this not allowed?

Edit: It works when I use %1 instead of FNAME, but it returns the whole path to the file as well, which is not what I'm looking for.

set FNAME=%@filename[%1]
set ANAME=%@altname[FNAME]

echo Name of the file:
echo %FNAME
echo.


echo Shortened name of the file:
echo %ANAME
echo.
aschipfl
  • 33,626
  • 12
  • 54
  • 99
adriana
  • 1
  • 1
  • Where are you getting `@filename` and `@altname` from? Those aren't normal batch variables. Regular batch variables are surrounded by `%`s on both sides when they're used, so right now your first line sets `FNAME` to `@filename[` and then there's a `1]` appended to the end. Meanwhile, `ANAME` doesn't get set to anything. But to answer your second question, it's perfectly valid to have a `@` in a variable name. – SomethingDark Dec 06 '22 at 23:30
  • I just followed the examples from this website https://jpsoft.com/help/f_altname.htm where echo %@altname["Long Name.exe"] LONGNA~1.EXE is the working example – adriana Dec 06 '22 at 23:41
  • 1
    The thing you found isn't batch, it's a completely unrelated language called tcc. – SomethingDark Dec 06 '22 at 23:51
  • Oh I'm sorry I thought they were the same things :( Thank you for clarifying – adriana Dec 06 '22 at 23:53
  • Are you actually using the software from the company in your link? Your code won't work otherwise. – SomethingDark Dec 06 '22 at 23:55
  • Yes, I am. The rest of the code seems to be working fine, except for the one function – adriana Dec 07 '22 at 00:05
  • Based on https://jpsoft.com/help/f_altname.htm, you probably need `set ANAME=%@altname["%FNAME"]` since all three examples on that page use quotes inside of the square brackets. – SomethingDark Dec 07 '22 at 00:08

0 Answers0