Microsoft Office Forums Naming files in folder, DOS vs Windows Explorer ASCII sequence

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-12-2015, 10:25 AM
equalizer88 equalizer88 is offline Naming files in folder, DOS vs Windows Explorer ASCII sequence Windows 7 32bit Naming files in folder, DOS vs Windows Explorer ASCII sequence Office 2010 32bit
Novice
Naming files in folder, DOS vs Windows Explorer ASCII sequence
 
Join Date: Jul 2015
Posts: 15
equalizer88 is on a distinguished road
Default Naming files in folder, DOS vs Windows Explorer ASCII sequence

I converted excel sheets to text files. I tried to name output files as



FileName = "C:\Users\VBA-beginner\Table_" & x & ".txt"

This will apply to WORD VBA as well.

Problem is sorting for humans and ASCII order used by computers is different. My file opened were in the order Table_1, ...10, ...

instead of Table_1, ..2,...3,. I needed files to be saved in a certain sequence, the human order.


Using windows explorer, the files appeared in human order, but using the F8 debugger, I found our sequence was different order. When I opened DOS window and used the dir command, it displayed ASCII order, which is how files get opened with VBA.

See blog for further explanation http://blog.codinghorror.com/sorting...al-sort-order/

Only solution is to use trailing zeros.

So here is my fix with leading and trailing format:

000_Table_000
001_Table_001...


x = Format(i , "000")
FileName = "C:\Users\VBA-beginner\" & x & "__Table_" & x & ".txt"

Last edited by equalizer88; 08-12-2015 at 03:20 PM. Reason: Generic username
Reply With Quote
  #2  
Old 08-12-2015, 03:10 PM
macropod's Avatar
macropod macropod is offline Naming files in folder, DOS vs Windows Explorer ASCII sequence Windows 7 64bit Naming files in folder, DOS vs Windows Explorer ASCII sequence Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,670
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

Your content doesn't have trailing 0s, it has leading 0s. That said, if you want to control the sort order of files whose name begins with 'Table', you can use:
x = Format(i , "000")
FileName = "C:\Users\VBA-beginner\Downloads\RPYC\CASS-Tables\Table_" & x & ".txt"
These files will have the same sort order as:
FileName = "C:\Users\VBA-beginner\Downloads\RPYC\CASS-Tables\" & x & "__Table_" & x & ".txt"
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #3  
Old 08-12-2015, 03:29 PM
equalizer88 equalizer88 is offline Naming files in folder, DOS vs Windows Explorer ASCII sequence Windows 7 32bit Naming files in folder, DOS vs Windows Explorer ASCII sequence Office 2010 32bit
Novice
Naming files in folder, DOS vs Windows Explorer ASCII sequence
 
Join Date: Jul 2015
Posts: 15
equalizer88 is on a distinguished road
Default

Macropod,

Yes, you are correct about only needing the leading numbers. I just did it for effect, easier to read.
That could confuse people, so your solution is the correct one for the forum.

Thank you.
Reply With Quote
Reply

Tags
batch save, filesort, naming files

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
File lists like windows explorer in onenote? karmajohn OneNote 0 07-22-2015 02:24 PM
Naming files in folder, DOS vs Windows Explorer ASCII sequence Windows Explorer search function S Fierro Windows 1 07-11-2014 06:11 AM
Naming files in folder, DOS vs Windows Explorer ASCII sequence Personalize windows explorer dianabanana Office 1 03-24-2014 08:10 PM
Naming files in folder, DOS vs Windows Explorer ASCII sequence How to enlarge Thumbnail View in XP Windows Explorer Gary Drumm Windows 3 02-10-2014 02:25 PM
Naming files in folder, DOS vs Windows Explorer ASCII sequence Windows explorer search problem...help!! NewSysAdmin Windows 1 03-08-2011 05:33 PM


All times are GMT -7. The time now is 05:22 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2019 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft