Solved

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

Posted on 2014-02-18
8
713 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 58

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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 56

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 70

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

Optimum High-Definition Video Viewing and Control

The ATEN VM0404HA 4x4 4K HDMI Matrix Switch supports 4K resolutions of UHD (3840 x 2160) and DCI (4096 x 2160) with refresh rates of 30 Hz (4:4:4) and 60 Hz (4:2:0). It is ideal for applications where the routing of 4K digital signals is required.

Question has a verified solution.

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

I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
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…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …

623 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