loop thru filenames in a directory

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
dehresmann
Posts: 3
Joined: 24 Jul 2017 13:46

loop thru filenames in a directory

#1 Post by dehresmann » 24 Jul 2017 13:54

I have a directory with filenames that I want to create a file from. the files are names below:

file1
file2
file3 ...


I want my final product to look like this:

catalog backuppiece 'Q:\dir\file1';
catalog backuppiece 'Q:\dir\file2';
catalog backuppiece 'Q:\dir\file3';

and so on...


any ideas? New to batch file.

thanks.

HS1234
Posts: 2
Joined: 25 Jul 2017 16:17

Re: loop thru filenames in a directory

#2 Post by HS1234 » 25 Jul 2017 16:38

dir /s /b *.* >filelist.txt

Hackoo
Posts: 103
Joined: 15 Apr 2014 17:59

Re: loop thru filenames in a directory

#3 Post by Hackoo » 26 Jul 2017 07:53

You don't specify any type of file to filter ?
So here is a startup script that you can modify it as your needs:

Code: Select all

@echo off
Mode 70,3 & Color 9E
Title  Loop thru filenames in a directory
Set "MasterFolder=%userprofile%\desktop"
Set "OutPut=List_Files.txt"
::Rem Ext is set to all files by wilcard *
Set "Ext=*"
If exist "%OutPut%" Del "%OutPut%"
echo(
echo           Please Wait a while we generate the output file ...
@For /f "delims=" %%a in ('Dir /s /b /A-D "%MasterFolder%\*.%Ext%"') Do (
cls
echo(
   echo "%%a"
   ( echo catalog backuppiece '%%a';)>> "%OutPut%"
   
)
Start "" "%OutPut%"

dehresmann
Posts: 3
Joined: 24 Jul 2017 13:46

Re: loop thru filenames in a directory

#4 Post by dehresmann » 26 Jul 2017 12:18

Sorry this is what the files look like:

catalog backuppiece 'K:\oradata\recovery\rman\ciprod\CIPROD_CIPROD_2055_16_20170725_950301792.BAK';
catalog backuppiece 'K:\oradata\recovery\rman\ciprod\CIPROD_CIPROD_2055_17_20170725_950301792.BAK';
catalog backuppiece 'K:\oradata\recovery\rman\ciprod\CIPROD_CIPROD_2055_18_20170725_950301792.BAK';
catalog backuppiece 'K:\oradata\recovery\rman\ciprod\CIPROD_CIPROD_2055_19_20170725_950301792.BAK';
catalog backuppiece 'K:\oradata\recovery\rman\ciprod\CIPROD_CIPROD_2055_1_20170725_950301792.BAK';
catalog backuppiece 'K:\oradata\recovery\rman\ciprod\CIPROD_CIPROD_2055_20_20170725_950301792.BAK';


Your bat worked. I had to modify the location from Desktop to K:\...

worked great thank you.

new to bat files.

want to learn though.

dehresmann
Posts: 3
Joined: 24 Jul 2017 13:46

Re: loop thru filenames in a directory

#5 Post by dehresmann » 26 Jul 2017 13:02

this change worked.

::Rem @For /f "delims=" %%a in ('Dir /s /b /A-D "%MasterFolder%\*.%Ext%"') Do (
@For /f "delims=" %%a in ('Dir /s /b /A-D "%MasterFolder%\CIPROD*.%Ext%"') Do (


I only want to pick up files like this:

catalog backuppiece 'K:\oradata\recovery\rman\ciprod\CIPROD_CIPROD_2055_20_20170725_950301792.BAK';


thanks.

Post Reply