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,084,752
Messages
5,379,649
Members
401,618
Latest member
Tapper1326

Some videos you may like

This Week's Hot Topics

  • VBA code giving errors and stopping Excel
    Hello Experts, I have this code being used to loop through files in a file path, and copy specific data to another sheet. It is giving me several...
  • Disable MsgBox message
    Morning, I have a userform where if i leave a ComboBox empty i see a MsgBox warning me that i must enter an invoice number. It is this MsgBox i...
  • Macro Recorder into VBA, Copy Paste Data Filled Cells
    Hi Everyone, I have a macro recorder file that takes a selection of data, copies, then pastes into a new sheet on ("A2:B2") The issue is my...
  • Number format changes while pasting into a cell
    Hi, I am trying to paste a number 180204524303 from an email to an excel cell, however, whenever i try to do so , the the paste value appears as...
  • Collating data
    Hello all. Could someone please help. I am trying to pull all column data from multiple sheets (24 I total so far) into 1 master sheet without...
  • Sum Multiple Columns Based on Multiple Criteria
    I am trying to consolidate data by summing columns G through M based on material, plant, vendor, and fiscal year being identical. The period does...
Top