Solved

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

Posted on 2014-02-18
8
702 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 56

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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 54

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

Create the perfect environment for any meeting

You might have a modern environment with all sorts of high-tech equipment, but what makes it worthwhile is how you seamlessly bring together the presentation with audio, video and lighting. The ATEN Control System provides integrated control and system automation.

Question has a verified solution.

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

Suggested Solutions

When you try to extract and to view the contents of a Microsoft Update Standalone Package (MSU) for Windows Vista, you cannot extract the files from the MSU. Here we are going to explain how to extract those hotfix details without using any third pa…
This article summaries thoughts and ideas from two years of sustained use. It provides good reasoning to make the jump to Windows 10.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

740 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