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
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
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))
 
Upvote 0
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>
 
Upvote 0

Forum statistics

Threads
1,215,050
Messages
6,122,868
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top