I need a workaround for a DIR problem
I need a workaround for a DIR problem
I have started to get a bunch of files from a program that gets them from the internet whose filename I want to change to match my naming system.
Numerous files have weird characters for example a zero byte in the middle of the filename. It seems that Windows 10 (Up to date) allows this other program to create a file like that.
I use DIR to process all the files but these files come back from DIR with a "?" in place of the weird characters. So when I used this modified name in a FBC NAME command it failed instead of finding the real file.
How can I get DIR to give me the unmodified Windows acceptable filename instead of the modified (with a ?) version?
Numerous files have weird characters for example a zero byte in the middle of the filename. It seems that Windows 10 (Up to date) allows this other program to create a file like that.
I use DIR to process all the files but these files come back from DIR with a "?" in place of the weird characters. So when I used this modified name in a FBC NAME command it failed instead of finding the real file.
How can I get DIR to give me the unmodified Windows acceptable filename instead of the modified (with a ?) version?
Re: I need a workaround for a DIR problem
hello
are the weird characters perhaps Unicode characters?
are the weird characters perhaps Unicode characters?
Re: I need a workaround for a DIR problem
perhaps this thread may help viewtopic.php?t=29674
-
- Posts: 1188
- Joined: May 08, 2006 21:58
- Location: Crewe, England
Re: I need a workaround for a DIR problem
You could try using findfirstfile/findnextfile variants instead of DIR.
Re: I need a workaround for a DIR problem
Where would I find findfirstfile/findnextfile ?
And yes it could be a Unicode character mixed in with the filename. I got this file from a friend in Europe and English is not his first language. I looked at the characters in the filename and it was an embedded zero byte in the middle of the filename.
And yes it could be a Unicode character mixed in with the filename. I got this file from a friend in Europe and English is not his first language. I looked at the characters in the filename and it was an embedded zero byte in the middle of the filename.
-
- Posts: 1188
- Joined: May 08, 2006 21:58
- Location: Crewe, England
Re: I need a workaround for a DIR problem
findfirstfile, etc are in winbase.bi. You will also need Win32_find_data in the same place. Suggest you look up in Microsoft Help.wallyg wrote: ↑Nov 10, 2023 18:24 Where would I find findfirstfile/findnextfile ?
And yes it could be a Unicode character mixed in with the filename. I got this file from a friend in Europe and English is not his first language. I looked at the characters in the filename and it was an embedded zero byte in the middle of the filename.
Re: I need a workaround for a DIR problem
And if you have characters outside the current codepage, you either need to go to -W strings, or enable UTF8 application as per application manifest
Re: I need a workaround for a DIR problem
No, I do not want to change my program to handle w-strings or work with different code pages. I should not have to. Dir should work as advertised. Give me the OS name of the files I requested. Will the FB command "Kill filename" work with the modified filename? Well, I know from spending several days tracking down an error that it does not. Neither FileExists nor FIleCopy either.
What possible reason would DIR change the name of a file so that it is unusable for any purpose?
I have no control over the name of the file I get and put into my system directory. Tell me how I can use the FB command NAME to change the offending name to one that is ok.
What possible reason would DIR change the name of a file so that it is unusable for any purpose?
I have no control over the name of the file I get and put into my system directory. Tell me how I can use the FB command NAME to change the offending name to one that is ok.
Re: I need a workaround for a DIR problem
Because there are 255 unique characters in any code page, and nearly 150,000 unique characters in Unicode. so not all of the characters in the latter can exist in the former. When the unicode character in the file name is one of the 149,745 chars that don't exist, that character gets replaced with a ?. It could fail, it could skip the character, or it could replace it, either way it results in a file name that isn't correct. This is a Windows thing, not FreeBasic.What possible reason would DIR change the name of a file so that it is unusable for any purpose?
Your choices are
1) Change the original file names that are downloaded
2) Do what everybody above is saying
3) Give up. Because...
...you can't
Re: I need a workaround for a DIR problem
If the original names don't matter you can use this bat file to rename all the files.
Change the extension and give the name you want. Eventually remove 'pause' in the loop.
In my example all the txt files are renamed in WLG<count>.wlg
Change the extension and give the name you want. Eventually remove 'pause' in the loop.
In my example all the txt files are renamed in WLG<count>.wlg
Code: Select all
SETLOCAL EnableDelayedExpansion
SET /A count=1
for %%F in (*.txt) do (
echo "count=":!count!:%%F
rename %%F WLG!count!.wlg
set /a count=count+1
pause)
goto :eof
pause
Re: I need a workaround for a DIR problem
No the original names are not important. Thanks for this.
Re: I need a workaround for a DIR problem
The GFile function family (in GLibs Gio) is designed to easy handle special characters in file names.
Regards
Regards
Re: I need a workaround for a DIR problem
Thank you so very much. This is exactly what I need. I need to study this carefully and then will implement it during the holidays. Thank you again.
Wally
Wally