Solved

2 Batch Files to List Files in First Folder Only then 1 for Subfolders

Posted on 2014-02-18
8
700 Views
Last Modified: 2014-02-18
Batch file 1 is executed above the folder and searches for all files in the root of the first folder and output  >>GetFilesinRootFolderONLY.txt

eg c:\hobo\GetFilesinRootFolderONLY.bat

c:\hobo\hobo\index.html
c:\hobo\hobo\home.html

sample output
index.html
home.html


Batch file 2 is executed above the folder and searches for all files in the subfolders of the root folder and output  >>GetFilesinRootSubFoldersONLY.txt

eg c:\hobo\GetFilesinRootSubFoldersONLY.bat

c:\hobo\hobo\pages\page1.html
c:\hobo\hobo\pages\page2.html

sample output
pages\page1.html
pages\page2.html
0
Comment
Question by:XGIS
8 Comments
 
LVL 18

Assisted Solution

by:x-men
x-men earned 125 total points
ID: 39866853
MS-DOS:
you can go:
dir c:\hobo\hobo >>GetFilesinRootFolderONLY.txt

and
dir /S c:\hobo\hobo\ >>GetFilesinRootSubFoldersONLY.txt
but it will include the root files.

Powershell:
dir c:\hobo\hobo\ | ?{$_.mode -like "d*"} | % {Get-ChildItem -Recurse $_} >>GetFilesinRootSubFoldersONLY.txt
0
 
LVL 7

Author Comment

by:XGIS
ID: 39867081
Unfortunately that yields metadata also not the EXACT "sample output"

to get the 1st request is almost like below... I just need to omit the directories

echo off
for /d %%a in (*.*) do dir /b /o:n "%%a" >>GetFilesInRootFolder.txt
0
 
LVL 54

Assisted Solution

by:Julian Hansen
Julian Hansen earned 125 total points
ID: 39867315
Is this what you are looking for.

Only files in root

dir /b /a-d

All files in subfolder

dir /b /a-d Subfolder

All files in subfolder recursive

dir /b /a-d /s Subfolder
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 53

Accepted Solution

by:
Bill Prew earned 125 total points
ID: 39867380
Not sure I exactly understand from the question description, but it sounds like you want all files in all directories contained in the base directory.  If that's the case then it can be done like this for your two needs:

for /d %%D in ("c:\hobo\*.*") do for %%F in ("&&~D") do echo %%~nxF>>GetFilesInRootFolder.txt

Open in new window

and
for /d %%D in ("c:\hobo\hobo\*.*") do for %%F in ("&&~D") do echo %%~nxF>>GetFilesInRootSubFolders.txt

Open in new window

~bp
0
 
LVL 7

Author Comment

by:XGIS
ID: 39867601
Hello JulianH,
Pls note it needs to go one folder down, the root of it, otherwise I would pick up my bat file in the list.   The example doesnt help... it should have looked like this to make it clear;
eg c:\hobo\GetFilesinRootFolderONLY.bat\hobo    where the last hobo is the root as shown next c:\hobo\hobo\index.html

This works 100% if the BAT is placed IN the ROOT of Hobo\Hobo  
for /d %%a in (*.*) do dir /b /o:n "%%a" >>GetFilesInRootFolder.txt
It ONLY yields filenames, no directory paths which is the required outcome..
This is bearable as only one ancillary row needs to be removed

and by doing this it at least orders directories to the top for easy removal
for /d %%a in (*.*) do dir /b /o:gen "%%a" >>GetFilesInRootFolder.txt

Unfortunately the 2nd suggestion from Bill produced &&~D in the text file.
0
 
LVL 69

Assisted Solution

by:Qlemo
Qlemo earned 125 total points
ID: 39867602
&& should be replaced by %% in above code lines. And the second is missing the folder name.
0
 
LVL 7

Author Comment

by:XGIS
ID: 39867625
Hello Qlemo... if I make that modification in Bill's sample it creates a text file with the single word Hobo.. even if I run the BAT from the Root

the for method is definitely the closest since it removes the file path
0
 
LVL 7

Author Closing Comment

by:XGIS
ID: 39867678
Unfortunately none of the answers were 100% , but all yielded a result, yet Bill's was closest.  I have run out of time to solve this and have gone to plan B. The result here was to be used in excel to generate CSPROJ xml for a dysfunctional VS project.   The solution was found by creating a standalone VS project and merging 2 projects together to yield the required path and file xml to correctly load the project.  Thankyou for your time and contributions.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question