Solved

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

Posted on 2014-02-18
8
699 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 52

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
 
LVL 52

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
Too many email signature changes to deal with?

Are you constantly being asked to update your organization's email signatures? Do they take up too much of your time? Wouldn't you love to be able to manage all signatures from one central location, easily design them and deploy them quickly to users. Well, you can!

 
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 68

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

Free book by J.Peter Bruzzese, Microsoft MVP

Are you using Office 365? Trying to set up email signatures but you’re struggling with transport rules and connectors? Let renowned Microsoft MVP J.Peter Bruzzese show you how in this exclusive e-book on Office 365 email signatures. Better yet, it’s free!

Question has a verified solution.

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

Suggested Solutions

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

912 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now