A very elementary request, but this had us searching all over the internet for solutions! We wished to get all the files in a folder, as we had saved multiple data files of Excel in one folder, and went about retrieving data from each file as and when required.
Trying to accomplish this is VBA is one thing, but what if we didn’t need to update it every time, and just needed it this once.. I wouldn’t want to waste my head over this by creating some complex VBA stuff.. then, where do we turn to? DOS!
It’s been a while since I heard that being used actually! But felt quite good trying to work it out.. Anyway, here’s the code to getting the filenames into one text file from a folder.
- Go to the file location in DOS using CD <PATH NAME>
- DIR /B /O:N > filename.txt
- DIR /B /O:N /S > filename.txt to get all files from subfolders as well
- DIR /B > filename.txt also works
- DIR > filename.txt gets all details other than file name too
Some basic stuff huh?!! But good to know it when you need it!