Solved

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

Posted on 2014-02-18
8
695 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 51

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 51

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 updates to deal with?

Do you feel like you are taking up all of your time constantly visiting users’ desks to make changes to email signatures? Wish you could manage all signatures from one central location, easily design them and deploy them quickly to users? Well, there is an easy way!

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
A Bare Metal Image backup allows for the restore of an entire system to a similar or dissimilar hardware. They are highly useful for migrations and disaster recovery. Bare Metal Image backups support Full and Incremental backups. Differential backup…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
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.

747 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

9 Experts available now in Live!

Get 1:1 Help Now