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 can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
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.


[TABLE="width: 270"]
<colgroup><col></colgroup><tbody>[TR]
[TD]C:\hjkh 3243 sdfsa\10Section 354.dgpx
[/TD]
[/TR]
[TR]
[TD]C:\hjkh 3243 sdfsa\11Section 354.dgpx[/TD]
[/TR]
[TR]
[TD]C:\hjkh 3243 sdfsa\12Section 354.dgpx
[/TD]
[/TR]
[TR]
[TD]C:\hjkh 3243 sdfsa\13Section 354.dgpx[/TD]
[/TR]
[TR]
[TD]C:\hjkh 3243 sdfsa\14Section 354.dgpx[/TD]
[/TR]
[TR]
[TD]C:\hjkh 3243 sdfsa\15Section 354.dgpx[/TD]
[/TR]
[TR]
[TD]C:\hjkh 3243 sdfsa\16Section 354.dgpx[/TD]
[/TR]
[TR]
[TD]C:\hjkh 3243 sdfsa\17Section 354.dgpx
[/TD]
[/TR]
[TR]
[TD]C:\hjkh 3243 sdfsa\18Section 354.dgpx[/TD]
[/TR]
[TR]
[TD]C:\hjkh 3243 sdfsa\19Section 354.dgpx[/TD]
[/TR]
[TR]
[TD]C:\hjkh 3243 sdfsa\1Section 354.dgpx[/TD]
[/TR]
[TR]
[TD]C:\hjkh 3243 sdfsa\20Section 354.dgpx[/TD]
[/TR]
[TR]
[TD]C:\hjkh 3243 sdfsa\21Section 354.dgpx[/TD]
[/TR]
[TR]
[TD]C:\hjkh 3243 sdfsa\22Section 354.dgpx[/TD]
[/TR]
[TR]
[TD]C:\hjkh 3243 sdfsa\23Section 354.dgpx[/TD]
[/TR]
[TR]
[TD]C:\hjkh 3243 sdfsa\24Section 354.dgpx[/TD]
[/TR]
[TR]
[TD]C:\hjkh 3243 sdfsa\25Section 354.dgpx[/TD]
[/TR]
[TR]
[TD]C:\hjkh 3243 sdfsa\26Section 354.dgpx[/TD]
[/TR]
[TR]
[TD]C:\hjkh 3243 sdfsa\27Section 354.dgpx[/TD]
[/TR]
[TR]
[TD]C:\hjkh 3243 sdfsa\28Section 354.dgpx[/TD]
[/TR]
[TR]
[TD]C:\hjkh 3243 sdfsa\29Section 354.dgpx[/TD]
[/TR]
[TR]
[TD]C:\hjkh 3243 sdfsa\2Section 354.dgpx[/TD]
[/TR]
[TR]
[TD]C:\hjkh 3243 sdfsa\30Section 354.dgpx[/TD]
[/TR]
[TR]
[TD]C:\hjkh 3243 sdfsa\3Section 354.dgpx[/TD]
[/TR]
[TR]
[TD]C:\hjkh 3243 sdfsa\4Section 354.dgpx[/TD]
[/TR]
[TR]
[TD]C:\hjkh 3243 sdfsa\5Section 354.dgpx[/TD]
[/TR]
[TR]
[TD]C:\hjkh 3243 sdfsa\6Section 354.dgpx
[/TD]
[/TR]
[TR]
[TD]C:\hjkh 3243 sdfsa\7Section 354.dgpx[/TD]
[/TR]
[TR]
[TD]C:\hjkh 3243 sdfsa\8Section 354.dgpx[/TD]
[/TR]
[TR]
[TD]C:\hjkh 3243 sdfsa\9Section 354.dgpx[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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