Not working whenfolder name changes - Generating Files path from folder and sub folders snb

afzalw

New Member
Joined
Jul 24, 2012
Messages
20
I use this code to get all files in a folder/subfolder, but the problem is if my folder has spaces in its name then it does not work. e.g in this code, c:\a\*.dgpx will work but c:\a a\*.dgpx will not work.

Code:
Sub GeneratingFilespathfromfolderandsubfolderssnb()
    c00 = "[B]c:\a\*.dgpx[/B]"
    sn = Application.Transpose(Split(CreateObject("wscript.shell").exec("cmd /c Dir " & c00 & " /b /s").stdout.readall, vbCrLf))
    Cells(1).Resize(UBound(sn)) = sn
End Sub
 

Jerry Sullivan

MrExcel MVP
Joined
Mar 18, 2010
Messages
8,787
Try this modification...

Code:
sn = Application.Transpose(Split(CreateObject("wscript.shell").exec("cmd /c Dir " _
    [B][COLOR="#0000CD"]& """" & c00 & """" &[/COLOR][/B] " /b /s").StdOut.ReadAll, vbCrLf))
 

afzalw

New Member
Joined
Jul 24, 2012
Messages
20
Thanks its working with folder name with spaces.
I have another thing regarding this code it gives the output in the following format for 30 files. Original name was "Section 354" and all these 30 files have numbering 1 to 30 as prefix. The results are not in proper order, can I get the results in the ascending order of their numberings.


C:\hjkh 3243 sdfsa\10Section 354.dgpx
C:\hjkh 3243 sdfsa\11Section 354.dgpx
C:\hjkh 3243 sdfsa\12Section 354.dgpx
C:\hjkh 3243 sdfsa\13Section 354.dgpx
C:\hjkh 3243 sdfsa\14Section 354.dgpx
C:\hjkh 3243 sdfsa\15Section 354.dgpx
C:\hjkh 3243 sdfsa\16Section 354.dgpx
C:\hjkh 3243 sdfsa\17Section 354.dgpx
C:\hjkh 3243 sdfsa\18Section 354.dgpx
C:\hjkh 3243 sdfsa\19Section 354.dgpx
C:\hjkh 3243 sdfsa\1Section 354.dgpx
C:\hjkh 3243 sdfsa\20Section 354.dgpx
C:\hjkh 3243 sdfsa\21Section 354.dgpx
C:\hjkh 3243 sdfsa\22Section 354.dgpx
C:\hjkh 3243 sdfsa\23Section 354.dgpx
C:\hjkh 3243 sdfsa\24Section 354.dgpx
C:\hjkh 3243 sdfsa\25Section 354.dgpx
C:\hjkh 3243 sdfsa\26Section 354.dgpx
C:\hjkh 3243 sdfsa\27Section 354.dgpx
C:\hjkh 3243 sdfsa\28Section 354.dgpx
C:\hjkh 3243 sdfsa\29Section 354.dgpx
C:\hjkh 3243 sdfsa\2Section 354.dgpx
C:\hjkh 3243 sdfsa\30Section 354.dgpx
C:\hjkh 3243 sdfsa\3Section 354.dgpx
C:\hjkh 3243 sdfsa\4Section 354.dgpx
C:\hjkh 3243 sdfsa\5Section 354.dgpx
C:\hjkh 3243 sdfsa\6Section 354.dgpx
C:\hjkh 3243 sdfsa\7Section 354.dgpx
C:\hjkh 3243 sdfsa\8Section 354.dgpx
C:\hjkh 3243 sdfsa\9Section 354.dgpx

<colgroup><col></colgroup><tbody>
</tbody>
 

Forum statistics

Threads
1,086,235
Messages
5,388,624
Members
402,127
Latest member
Jemx

Some videos you may like

This Week's Hot Topics

Top