Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: How can you tell an old program to use shrt names?  (Read 3572 times)

0 Members and 1 Guest are viewing this topic.

Geek-9pm

    Topic Starter

    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
How can you tell an old program to use shrt names?
« on: September 05, 2017, 09:26:38 PM »
Yes, I am talking about very old programs. Some will choke on a long file name or a file name with some odd chars in it.
Was there not some way lyou can make the old program use the short  name? And when it writes the short name file back out to the system, it inherits the long file name automatically. Is that right?

So I want to make a batch file that does this.
 find the short name of a file that has a long name.
 call the old program  using short name
 let the old program write the short name file back to the system
 report if an error was made

Is that possible?  Just asking.
If you ignore  this, I will assume it is a bad idea.  :-\

BC_Programmer


    Mastermind
  • Typing is no substitute for thinking.
  • Thanked: 1140
    • Yes
    • Yes
    • BC-Programming.com
  • Certifications: List
  • Computer: Specs
  • Experience: Beginner
  • OS: Windows 11
Re: How can you tell an old program to use shrt names?
« Reply #1 on: September 05, 2017, 09:48:19 PM »
I'm sure salmon Trout or one of the other more experienced batch folks can give a better solution than I.

The first issue is that no- when a program that doesn't support long file names (MS-DOS or 16-bit windows programs) writes back to the file, the long file name is not really preserved. There might be some very specific cases where it is- in particular, it depends if the program is writing to that file specifically, or deleting the existing file and recreating it. That was a common approach to saving files so it is much more common to find that the long name is basically removed altogether.

However, you can pretty easily workaround this with the batch. You can get the short name, run the program, wait for it to exit, and then afterwards you rename (move) the short named file to the original long name.

This has two batch files. One which is used to get the short file name, which I called getshort.bat:

Code: [Select]
@ECHO OFF
echo %~s1

and another to make use of it and run the program, which I've called runshort.bat:

Code: [Select]
@echo off
echo running program "%1" with shortened filename of "%2"
set fullname=%2
for /f %%p in ('getshort %2') do set shortfile=%%p
echo shortfilename is %shortfile%
start /wait %1 %shortfile%
move %shortfile% %fullname%

which is executed as runshort "C:\Program files (x86)\oldsoft\oldprogram.exe" "C:\Users\My User Account\Documents\Some Weird Folder\Unusually titled files\a study on the various kinds of birds which have nested within my beard.opd"

which will run the program with the short file name, and then afterwards rename that short name to the long name; if the program did nothing or rewrote the file properly, it will fail and do nothing, but if the program rewrote the file and the long name was lost, renaming the short name to the long name will effectively restore it.

The only caveat is that it might not have the same short file name afterwards, so MRUs within the old program might not function correctly.

Since I'm on 64-bit windows, there are short names, but I don't have any way to directly run older applications, so I can't directly test it with such a program.

I was trying to dereference Null Pointers before it was cool.

Geek-9pm

    Topic Starter

    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: How can you tell an old program to use shrt names?
« Reply #2 on: September 06, 2017, 01:40:01 AM »
Thanks BC,
The program I have is not a 16 bit program. I think I will that on my 64 bit machine and see. As it is now, if a file goes beyund the 8.3 spec, I get a bad file mode.
I  wrote  it so that it writes to a temporary file and then at the end it copies the temp to the original name.

So for the present, I have to rename t he files my hand. I still have a lot of flies to process, so I was hoping for a solution that  would let me automate the job.

Well,  it is one of my own programs so I should re-write it in a newer compiler. But it was easier for me to just ask for a quick workaround.
Thanks again.

(Now I expect  Salmon trout will come along and do it in lone line.)  8)

Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: How can you tell an old program to use shrt names?
« Reply #3 on: September 06, 2017, 08:45:24 AM »
16bit programs cannot run on 64bit OS last time I checked.

But the provided solution should work if you pass it the short file name.  It should also be able to write to the short file name.

Easy enough to test that theory from the cmd prompt.
Code: [Select]
H:\>type nul>"really long file name 123456789.txt"

H:\>dir /x really*
 Volume in drive H is DATA
 Volume Serial Number is D2F3-49FA

 Directory of H:\

09/06/2017  09:42 AM                 0 REALLY~1.TXT really long file name 123456789.txt
               1 File(s)              0 bytes
               0 Dir(s)  168,122,675,200 bytes free

H:\>echo blah>really~1.txt

H:\>type really~1.txt
blah

H:\>notepad really~1.txt

H:\>type really~1.txt
blah
notepad edit