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,082,258
Messages
5,364,081
Members
400,778
Latest member
Canadian Sal

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top