Discussion Locked

WIN2K DOS Batch Program

0 helpful
8 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I am trying create a script to copy files with the same extension out of multiple directories into a single directory.

It looks a little like this..

c:\mydir\dir1\file1.RTA
c:\mydir\dir2\file2.RTA
c:\mydir\dir3\file3.RTA

..into a single directory..

c:\newdir\file1.RTA
c:\newdir\file2.RTA
c:\newdir\file3.RTA

I can't use XCOPY because it copies the subdirectories, which I don't want. So far I've created a small batch file that pipes the output from..

DIR c:\mydir\*.RTA /S /B > temp.txt

..giving me the full paths of all the files which looks like..

c:\mydir\dir1\file1.RTA
c:\mydir\dir2\file2.RTA
c:\mydir\dir3\file3.RTA

All I need to do is create some kind of a filter to add in COPY before each path in the file and the destination. So the TEMP.BAT file will look like..

COPY c:\mydir\dir1\file1.RTA c:\newdir\
COPY c:\mydir\dir2\file2.RTA c:\newdir\
COPY c:\mydir\dir3\file3.RTA c:\newdir\

But I don't know how to do that in a DOS environment.

Anyone know how or an easier way to do it?

8 replies

by willcomp

You were on the right track with xcopy. It will not copy subdirectories unless the /s switch is included.

xcopy was a great improvement over the copy command in the good ol' DOS days.

Dalton

by wreeson

You didn't actually answer my question.

The directories that the files are in are randomly named. As far as I can see, you need the /S switch to get xcopy to go recursively into the directories to find the *.RTA files.

But then it copies the directories themselves, solving nothing

by wreeson

You didn't actually answer my question.

The directories that the files are in are randomly named. As far as I can see, you need the /S switch to get xcopy to go recursively into the directories to find the *.RTA files.

But then it copies the directories themselves, solving nothing.

by willcomp

Well, either I don't understand or didn't take you far enough. Can use a simple batch file.

copyrta.bat

cd\mydir\dir1
xcopy *.rta c:\newdir
cd\mydir\dir2
xcopy *.rta c:\newdir
cd\mydir\dir3
xcopy *.rta c:\newdir

You can also use copy in place of xcopy, but xcopy is faster.

If this isn't what you're looking for, expound a little, if possible.

Dalton

by wreeson

The directories are randomly generated by the program creating the files. These directories change on a daily basis. So I can't just write the directory path into the batch file.

I can pull this information out the the directories (each day) and into a file.

c:\mydir\dir1\file1.RTA
c:\mydir\dir2\file2.RTA
c:\mydir\dir3\file3.RTA

But I need to add in COPY before those source paths and a destination. If this was in Linux I could use perl scripts to read the text and add those in before and after the lines. But I don't know how or if it's possible in DOS.

by juergen hartl

On Error Resume Next
Ordner="c:\mydir"
DateiFilter="RTA"
destFolder="g:\copyRTA\"
Set ie4=CreateObject("InternetExplorer.Application")
ie4.navigate ("about:blank"): ie4.visible=1
Set FSys=CreateObject("Scripting.FileSystemObject")
Set TheFolder = FSys.GetFolder(Ordner)
ie4.document.body.innerHTML="

"
SubFolders TheFolder, DateiFilter
MsgBox "Done"
Set ie4=nothing: Set fSys=nothing

Sub SubFolders(ByVal AFolder, TheExtension)
ie4.document.all.idOutput.insertAdjacentHTML "BeforeEnd", strOut
ShowFilesWithExtensionIn AFolder, TheExtension
Set MoreFolders = AFolder.SubFolders
For Each TempFolder In MoreFolders
SubFolders TempFolder, TheExtension
Next
End Sub

Sub ShowFilesWithExtensionIn(AFolder,TheExtension)
On Error Resume Next
'Dim AFile, TheFiles,s, header
header="

Inhalt von: " & folderspec & "

"
Set TheFiles = AFolder.Files
For Each AFile In TheFiles
If UCase(FSys.GetExtensionName(AFile.Path)) = TheExtension Then
s=AFile.path
s = s & "
"
ie4.document.all.idOutput.insertAdjacentHTML "BeforeEnd", s
fsys.CopyFile Afile.path, destFolder & afile.name, false
End If
Next
End Sub

What this script does is: At the starting folder "C:\mydir" it recursively goes through all subfolders looking for a file with the extension "RTA" and copies that file to the "G:\copyRTA\"
The options are set in line 2,3 and 4.
Hope this helps

by jmasuda

In Win2K version of DOS, just do:
For /R c:\mydir %i In (*.RTA) Do XCOPY "%i" c:\newdir

This discussion is closed to new replies.