PC Review


Reply
Thread Tools Rate Thread

DIR fn when filename has non-ANSI characters

 
 
simonc
Guest
Posts: n/a
 
      1st Jul 2008
I want to use the DIR function to extract the names of files in a directory
and write them into a spreadsheet. As the filenames are all in Russian they
are all non-ANSI characters and DIR simply returns a question mark character
for each letter in the file name. Is there a way of getting DIR to read
non-ANSI?

Grateful for advice.
 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      1st Jul 2008
I'm guessing, but I think it really has to do with the operating system and
not Excel. there are regional settings in the registry that determines the
language and Excel rreturns the same values that DOS would return. To help
determine if it is an excel problem or a windows Problem try the following.

Open a DOS window by going to start button - Press Run - In text box enter
exe.cmd and press OK. the enter DIR and your filename. You can change
drives by typing H: and changing folder by typing cd TEMP (you can also use
wildcards like * and ? with cd)

"simonc" wrote:

> I want to use the DIR function to extract the names of files in a directory
> and write them into a spreadsheet. As the filenames are all in Russian they
> are all non-ANSI characters and DIR simply returns a question mark character
> for each letter in the file name. Is there a way of getting DIR to read
> non-ANSI?
>
> Grateful for advice.

 
Reply With Quote
 
simonc
Guest
Posts: n/a
 
      1st Jul 2008
A DOS listing in a comand window returns the question mark character as well.
I will have to find some other way to get these file names into a
spreadsheet. I can do it manually, one file at a time, in Explorer if I use
file rename and copy the filename text without actually changing it, but
there are a lot of files...

"Joel" wrote:

> I'm guessing, but I think it really has to do with the operating system and
> not Excel. there are regional settings in the registry that determines the
> language and Excel rreturns the same values that DOS would return. To help
> determine if it is an excel problem or a windows Problem try the following.
>
> Open a DOS window by going to start button - Press Run - In text box enter
> exe.cmd and press OK. the enter DIR and your filename. You can change
> drives by typing H: and changing folder by typing cd TEMP (you can also use
> wildcards like * and ? with cd)
>
> "simonc" wrote:
>
> > I want to use the DIR function to extract the names of files in a directory
> > and write them into a spreadsheet. As the filenames are all in Russian they
> > are all non-ANSI characters and DIR simply returns a question mark character
> > for each letter in the file name. Is there a way of getting DIR to read
> > non-ANSI?
> >
> > Grateful for advice.

 
Reply With Quote
 
Roger Govier
Guest
Posts: n/a
 
      1st Jul 2008
Hi Simon

Why do you want to do it with DIR?
Could you not use the File Scripting Object to do it directly through VBA?

Here is some code posted by Jim Cone which should do what you want.

Sub ListAllFilesInFolder()
'Jim Cone - Portland Oregon - USA
Dim strPath As String
Dim oFSO As Object
Dim oFile As Object
Dim oFolder As Object
Dim N As Long

strPath = "C:\Program Files\Microsoft Office\Office11"

N = 1
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(strPath)
Cells(N, 1).Value = oFolder.Path
N = N + 1
For Each oFile In oFolder.Files
Cells(N, 2).Value = oFile.Name
N = N + 1
Next 'oFile
Set oFSO = Nothing
Set oFile = Nothing
Set oFolder = Nothing
End Sub



--
Regards
Roger Govier

"simonc" <(E-Mail Removed)> wrote in message
news:87807937-DD3F-4403-AEBF-(E-Mail Removed)...
> A DOS listing in a comand window returns the question mark character as
> well.
> I will have to find some other way to get these file names into a
> spreadsheet. I can do it manually, one file at a time, in Explorer if I
> use
> file rename and copy the filename text without actually changing it, but
> there are a lot of files...
>
> "Joel" wrote:
>
>> I'm guessing, but I think it really has to do with the operating system
>> and
>> not Excel. there are regional settings in the registry that determines
>> the
>> language and Excel rreturns the same values that DOS would return. To
>> help
>> determine if it is an excel problem or a windows Problem try the
>> following.
>>
>> Open a DOS window by going to start button - Press Run - In text box
>> enter
>> exe.cmd and press OK. the enter DIR and your filename. You can change
>> drives by typing H: and changing folder by typing cd TEMP (you can also
>> use
>> wildcards like * and ? with cd)
>>
>> "simonc" wrote:
>>
>> > I want to use the DIR function to extract the names of files in a
>> > directory
>> > and write them into a spreadsheet. As the filenames are all in Russian
>> > they
>> > are all non-ANSI characters and DIR simply returns a question mark
>> > character
>> > for each letter in the file name. Is there a way of getting DIR to read
>> > non-ANSI?
>> >
>> > Grateful for advice.


 
Reply With Quote
 
simonc
Guest
Posts: n/a
 
      1st Jul 2008
Roger

This looks more promising. Unfortunately some of these files are in folders
which have Russian characters in the name and when I paste the folder name
into strPath it again substitutes question marks for each non-ANSI character.
Is there a way round this?

Could you also tell me how to set the macro so it will recognise folders as
well as files when it is going through the For...Next loop?

Thanks

Simon

"Roger Govier" wrote:

> Hi Simon
>
> Why do you want to do it with DIR?
> Could you not use the File Scripting Object to do it directly through VBA?
>
> Here is some code posted by Jim Cone which should do what you want.
>
> Sub ListAllFilesInFolder()
> 'Jim Cone - Portland Oregon - USA
> Dim strPath As String
> Dim oFSO As Object
> Dim oFile As Object
> Dim oFolder As Object
> Dim N As Long
>
> strPath = "C:\Program Files\Microsoft Office\Office11"
>
> N = 1
> Set oFSO = CreateObject("Scripting.FileSystemObject")
> Set oFolder = oFSO.GetFolder(strPath)
> Cells(N, 1).Value = oFolder.Path
> N = N + 1
> For Each oFile In oFolder.Files
> Cells(N, 2).Value = oFile.Name
> N = N + 1
> Next 'oFile
> Set oFSO = Nothing
> Set oFile = Nothing
> Set oFolder = Nothing
> End Sub
>
>
>
> --
> Regards
> Roger Govier
>


 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      1st Jul 2008
I think you need to change your registry. There was a problem a couple of
weeks ago the somebody in Israel was defaulting to Turkish language. Not
sure which registry seting is wrong but found an Internet explorer setting in
the website below

http://msdn.microsoft.com/en-us/library/ms902920.aspx

"simonc" wrote:

> Roger
>
> This looks more promising. Unfortunately some of these files are in folders
> which have Russian characters in the name and when I paste the folder name
> into strPath it again substitutes question marks for each non-ANSI character.
> Is there a way round this?
>
> Could you also tell me how to set the macro so it will recognise folders as
> well as files when it is going through the For...Next loop?
>
> Thanks
>
> Simon
>
> "Roger Govier" wrote:
>
> > Hi Simon
> >
> > Why do you want to do it with DIR?
> > Could you not use the File Scripting Object to do it directly through VBA?
> >
> > Here is some code posted by Jim Cone which should do what you want.
> >
> > Sub ListAllFilesInFolder()
> > 'Jim Cone - Portland Oregon - USA
> > Dim strPath As String
> > Dim oFSO As Object
> > Dim oFile As Object
> > Dim oFolder As Object
> > Dim N As Long
> >
> > strPath = "C:\Program Files\Microsoft Office\Office11"
> >
> > N = 1
> > Set oFSO = CreateObject("Scripting.FileSystemObject")
> > Set oFolder = oFSO.GetFolder(strPath)
> > Cells(N, 1).Value = oFolder.Path
> > N = N + 1
> > For Each oFile In oFolder.Files
> > Cells(N, 2).Value = oFile.Name
> > N = N + 1
> > Next 'oFile
> > Set oFSO = Nothing
> > Set oFile = Nothing
> > Set oFolder = Nothing
> > End Sub
> >
> >
> >
> > --
> > Regards
> > Roger Govier
> >

>

 
Reply With Quote
 
Roger Govier
Guest
Posts: n/a
 
      1st Jul 2008
Hi Simon

Could you not just create a folder called C:\Simon and drag all of the files
to that location?

--
Regards
Roger Govier

"simonc" <(E-Mail Removed)> wrote in message
news:4081D251-D2B7-4DD5-A290-(E-Mail Removed)...
> Roger
>
> This looks more promising. Unfortunately some of these files are in
> folders
> which have Russian characters in the name and when I paste the folder name
> into strPath it again substitutes question marks for each non-ANSI
> character.
> Is there a way round this?
>
> Could you also tell me how to set the macro so it will recognise folders
> as
> well as files when it is going through the For...Next loop?
>
> Thanks
>
> Simon
>
> "Roger Govier" wrote:
>
>> Hi Simon
>>
>> Why do you want to do it with DIR?
>> Could you not use the File Scripting Object to do it directly through
>> VBA?
>>
>> Here is some code posted by Jim Cone which should do what you want.
>>
>> Sub ListAllFilesInFolder()
>> 'Jim Cone - Portland Oregon - USA
>> Dim strPath As String
>> Dim oFSO As Object
>> Dim oFile As Object
>> Dim oFolder As Object
>> Dim N As Long
>>
>> strPath = "C:\Program Files\Microsoft Office\Office11"
>>
>> N = 1
>> Set oFSO = CreateObject("Scripting.FileSystemObject")
>> Set oFolder = oFSO.GetFolder(strPath)
>> Cells(N, 1).Value = oFolder.Path
>> N = N + 1
>> For Each oFile In oFolder.Files
>> Cells(N, 2).Value = oFile.Name
>> N = N + 1
>> Next 'oFile
>> Set oFSO = Nothing
>> Set oFile = Nothing
>> Set oFolder = Nothing
>> End Sub
>>
>>
>>
>> --
>> Regards
>> Roger Govier
>>

>

 
Reply With Quote
 
pgarcia
Guest
Posts: n/a
 
      24th Sep 2008
Hello,
Is there a way to include sub folders? Also, it gives you two lines in
excel, A1 has the dir path and B2 gives you the file name with extention, is
there a way to include them both?
e.g. c:\my clone files\clone to delete\clone1.txt

"Roger Govier" wrote:

> Hi Simon
>
> Why do you want to do it with DIR?
> Could you not use the File Scripting Object to do it directly through VBA?
>
> Here is some code posted by Jim Cone which should do what you want.
>
> Sub ListAllFilesInFolder()
> 'Jim Cone - Portland Oregon - USA
> Dim strPath As String
> Dim oFSO As Object
> Dim oFile As Object
> Dim oFolder As Object
> Dim N As Long
>
> strPath = "C:\Program Files\Microsoft Office\Office11"
>
> N = 1
> Set oFSO = CreateObject("Scripting.FileSystemObject")
> Set oFolder = oFSO.GetFolder(strPath)
> Cells(N, 1).Value = oFolder.Path
> N = N + 1
> For Each oFile In oFolder.Files
> Cells(N, 2).Value = oFile.Name
> N = N + 1
> Next 'oFile
> Set oFSO = Nothing
> Set oFile = Nothing
> Set oFolder = Nothing
> End Sub
>
>
>
> --
> Regards
> Roger Govier
>
> "simonc" <(E-Mail Removed)> wrote in message
> news:87807937-DD3F-4403-AEBF-(E-Mail Removed)...
> > A DOS listing in a comand window returns the question mark character as
> > well.
> > I will have to find some other way to get these file names into a
> > spreadsheet. I can do it manually, one file at a time, in Explorer if I
> > use
> > file rename and copy the filename text without actually changing it, but
> > there are a lot of files...
> >
> > "Joel" wrote:
> >
> >> I'm guessing, but I think it really has to do with the operating system
> >> and
> >> not Excel. there are regional settings in the registry that determines
> >> the
> >> language and Excel rreturns the same values that DOS would return. To
> >> help
> >> determine if it is an excel problem or a windows Problem try the
> >> following.
> >>
> >> Open a DOS window by going to start button - Press Run - In text box
> >> enter
> >> exe.cmd and press OK. the enter DIR and your filename. You can change
> >> drives by typing H: and changing folder by typing cd TEMP (you can also
> >> use
> >> wildcards like * and ? with cd)
> >>
> >> "simonc" wrote:
> >>
> >> > I want to use the DIR function to extract the names of files in a
> >> > directory
> >> > and write them into a spreadsheet. As the filenames are all in Russian
> >> > they
> >> > are all non-ANSI characters and DIR simply returns a question mark
> >> > character
> >> > for each letter in the file name. Is there a way of getting DIR to read
> >> > non-ANSI?
> >> >
> >> > Grateful for advice.

>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      24th Sep 2008
Check your earlier thread.

pgarcia wrote:
>
> Hello,
> Is there a way to include sub folders? Also, it gives you two lines in
> excel, A1 has the dir path and B2 gives you the file name with extention, is
> there a way to include them both?
> e.g. c:\my clone files\clone to delete\clone1.txt
>
> "Roger Govier" wrote:
>
> > Hi Simon
> >
> > Why do you want to do it with DIR?
> > Could you not use the File Scripting Object to do it directly through VBA?
> >
> > Here is some code posted by Jim Cone which should do what you want.
> >
> > Sub ListAllFilesInFolder()
> > 'Jim Cone - Portland Oregon - USA
> > Dim strPath As String
> > Dim oFSO As Object
> > Dim oFile As Object
> > Dim oFolder As Object
> > Dim N As Long
> >
> > strPath = "C:\Program Files\Microsoft Office\Office11"
> >
> > N = 1
> > Set oFSO = CreateObject("Scripting.FileSystemObject")
> > Set oFolder = oFSO.GetFolder(strPath)
> > Cells(N, 1).Value = oFolder.Path
> > N = N + 1
> > For Each oFile In oFolder.Files
> > Cells(N, 2).Value = oFile.Name
> > N = N + 1
> > Next 'oFile
> > Set oFSO = Nothing
> > Set oFile = Nothing
> > Set oFolder = Nothing
> > End Sub
> >
> >
> >
> > --
> > Regards
> > Roger Govier
> >
> > "simonc" <(E-Mail Removed)> wrote in message
> > news:87807937-DD3F-4403-AEBF-(E-Mail Removed)...
> > > A DOS listing in a comand window returns the question mark character as
> > > well.
> > > I will have to find some other way to get these file names into a
> > > spreadsheet. I can do it manually, one file at a time, in Explorer if I
> > > use
> > > file rename and copy the filename text without actually changing it, but
> > > there are a lot of files...
> > >
> > > "Joel" wrote:
> > >
> > >> I'm guessing, but I think it really has to do with the operating system
> > >> and
> > >> not Excel. there are regional settings in the registry that determines
> > >> the
> > >> language and Excel rreturns the same values that DOS would return. To
> > >> help
> > >> determine if it is an excel problem or a windows Problem try the
> > >> following.
> > >>
> > >> Open a DOS window by going to start button - Press Run - In text box
> > >> enter
> > >> exe.cmd and press OK. the enter DIR and your filename. You can change
> > >> drives by typing H: and changing folder by typing cd TEMP (you can also
> > >> use
> > >> wildcards like * and ? with cd)
> > >>
> > >> "simonc" wrote:
> > >>
> > >> > I want to use the DIR function to extract the names of files in a
> > >> > directory
> > >> > and write them into a spreadsheet. As the filenames are all in Russian
> > >> > they
> > >> > are all non-ANSI characters and DIR simply returns a question mark
> > >> > character
> > >> > for each letter in the file name. Is there a way of getting DIR to read
> > >> > non-ANSI?
> > >> >
> > >> > Grateful for advice.

> >


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to convert Characters between Unicode and ANSI =?Utf-8?B?RmNvTWFyaXNjYWw=?= Microsoft Excel Programming 0 24th Aug 2006 10:47 PM
ANSI print control characters =?Utf-8?B?TkJC?= Microsoft Word Document Management 1 18th Apr 2005 08:39 PM
RE: ANSI Encoding 1252 - not all characters convert? Jon Skeet [C# MVP] Microsoft Dot NET Framework 0 21st Jul 2004 05:55 PM
Re: ANSI Encoding 1252 - not all characters convert? Jay B. Harlow [MVP - Outlook] Microsoft Dot NET Framework 0 20th Jul 2004 10:41 PM
ANSI Characters Gregory La Due Windows XP General 0 10th Aug 2003 02:13 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:13 PM.