Computing.Net > Forums > Disk Operating System > copying files to one directory

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

copying files to one directory

Reply to Message Icon

Name: Miskva3
Date: January 7, 2003 at 08:51:15 Pacific
OS: w98
CPU/Ram: P3/456mb
Comment:

I have got the following issue

What I have, is a cd-rom, containing a bunch of files.

What I need: some of these files (wildcard notation known in advance) need to be copied to harddisk, to a certain directory, but: the subdirectory information may be lost !

In other words, something like this:

mkdir c:\target_dir
xcopy e:\p*.ext c:\target_dir /S

BUT: I do NOT want subdirs to be created in c:\target_dir, all files must be in the root of c:\target_dir .. ! (supposing some files p*.ext are located in some subdirs on e:)



Sponsored Link
Ads by Google

Response Number 1
Name: Secret_Doom
Date: January 7, 2003 at 11:20:36 Pacific
Reply:

Hello, Miskva. I've seen your subject at alt.msdos.batch. You got plenty of solutions indeed. However, at my point of view, none of them were 100% satisfactory, because most of them used 3rd party applications. The one which avoided that, William Allen's script, is very slow.

I were able to develop a solution of my own, but when I tested it with US's COUNTRY code (which I reckon is the one you use, date format MM-DD-YY), it failed. Nevertheless, I might addapt it if I get some extra time (I like the challenge hehe).

Anyway, enough of off-topic conversation!! Here we go, your script:

===== BATCH SCRIPT BEGIN =====
@echo off
if "%1"=="GoTo" goto %2

:: Set SOURCE and DESTination below
:: Wilcards may be used on SOURCE
set SOURCE=e:\p*.txt
set DEST=c:\target_dir

:: Addapted assembler code - original by William Allen
echo e100 86 06 46 01 86 06 47 01 BA 46 01 B9 01 00 BB 00> %temp%.\T1.COM
echo e110 00 B4 3F CD 21 09 C0 74 28 BA 46 01 B9 01 00 80>> %temp%.\T1.COM
echo e120 3E 46 01 3E 75 05 C6 06 46 01 2D 80 3E 47 01 0A>> %temp%.\T1.COM
echo e130 75 06 BA 43 01 B9 04 00 BB 01 00 B4 40 CD 21 EB>> %temp%.\T1.COM
echo e140 BF CD 20 25 50 25 0A 00>> %temp%.\T1.COM
for %%? in (rcx 48 w q) do echo %%?>> %temp%.\T1.COM
type %temp%.\T1.COM |DEBUG %temp%.\T1.COM > nul
if not exist %DEST%.\nul md %DEST%
XCOPY /F /I /L /N /S /Y %SOURCE% %DEST% |FIND ":\" |%temp%.\T1.COM > %temp%.\T2.BAT
set P=call %0 GoTo copy %=%
call %temp%.\T2.BAT
for %%? in (T1.COM T2.BAT) do del %temp%.\%%?
set P=
goto eof

:copy
:: To acticate script, remove "echo.{demo}" from next line
echo.{demo}copy /-y %3 %DEST%

:eof
===== BATCH SCRIPT END =====

The script is de-activated. If you run it like that, it will display the actions it would take if active. If those are the desired actions, activate the script (read commented lines for doing so).

Currently, the script will prompt to overwrite any existant files on the destination. To make if overwrite automatically, change the string "/-y" for "/y" on the COPY line (the last red one).

The script was developed and tested under Windows 98 SE. That asm code may be avoided, if you think it's bad to have it (I see no problem).

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br

_______________________________________________________________________________________


0

Response Number 2
Name: Miskva3
Date: January 7, 2003 at 11:52:20 Pacific
Reply:

Hi Doom,

I unfortunately didnt find the time yet to test these things, but I certainly will .. Guess it *IS* impossible to do this without 3rd party tools ...

I will start trying the solution you just entered here ..



0

Response Number 3
Name: Miskva3
Date: January 7, 2003 at 12:06:41 Pacific
Reply:

It certainly works, the example you gave here ! Thanks ... I see a lot of code I never use .. just found out 'find' on DOS is like 'grep'

Anyway, got some questions though :

- it does not work, if source and target are on the same disk (not really a problem .. just mentioning)
- a problem is, that when finding files with same name, he stops and asks .. any way to automatically overwrite (or just not, doesnt matter)
- Can I use this script, for professional use ?


0

Response Number 4
Name: onefromme2003
Date: January 7, 2003 at 17:15:04 Pacific
Reply:

Those batch files look really complicated, like something you might want to run through pgp with a skeleton key.


0

Response Number 5
Name: Secret_Doom
Date: January 7, 2003 at 18:44:35 Pacific
Reply:

Hello, Miskva.

> Guess it *IS* impossible to do
> this without 3rd party tools ...

It's not impossible. You've already seen a solution without 3rd party - that one from William Allen. However, as I've said before, it's very slow. Anyway, I'll try to make a better one. I actually already have most of the idea ready (just have to write it...)

> - it does not work, if source and
> target are on the same disk (not
> really a problem .. just mentioning)

Hmmm. I can't check that right now, but I reckon it will fail only if destination is a location inside source. XCOPY would say something like "can't make a cycle copy". You can't copy files from the source in a way they would be processed again, since destination is inside source, because it would make an endless loop. Nevertheless, I think it will work in other situations, even if source and destination are on the same drive. However, I could be wrong about this. I'll check it soon.

> - a problem is, that when finding
> files with same name, he stops and
> asks .. any way to automatically
> overwrite (or just not, doesnt matter)

Read again my post - I wrote:

> Currently, the script will prompt
> to overwrite any existant files on
> the destination. To make if overwrite
> automatically, change the string "/-y"
> for "/y" on the COPY line (the last
> red one).

So, to avoid the prompt, making it overwrite, change this line;

copy /-y %3 %DEST%

Into this:

copy /y %3 %DEST%

If you want to get no prompt and do NOT overwrite, put this line instead of the line above:

if not exist %DEST%.\%3 copy %3 %DEST%

> - Can I use this script, for
> professional use ?

Nobody have ever asked me that. No one have asked before if they could use my free help to their own profit, without giving anything back to me... I do feel used sometimes. It is very nice of you asking it, I don't mind how you use it. I actually hope it is as useful as possible to you. I'm just happy to help people and gain knowledge with that. I don't need money for living, yet.

That's it. If you go trying to understand the batch script, it will be difficult on the part where I used the assembler code. The thing is: T1.COM will read input from stdin, prefix each line with "%P%" and replacing any ">" signs with "-", and will output to stdout.

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br


0

Related Posts

See More



Response Number 6
Name: Secret_Doom
Date: January 7, 2003 at 20:06:48 Pacific
Reply:

Hello again, Miskva.

About that script to get the most recent file:

- Is that for personal use, or will you distribute it?

- What is your country code, and what is the exact date and time format from it? Actually, I need to know how the appear in DIR listings.

- The country code 002 has a date format YYYY-MM-DD. If by any chance you like that format and you prefer or see no problem in changing your country code to that one, it will make things easier.

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br


0

Response Number 7
Name: Miskva3
Date: January 8, 2003 at 01:18:27 Pacific
Reply:

OK, thanks for the reply .. but please put the remarks about the other program (the one with the 'most recent file on disk') in the other thread .. Cause it is getting complicated .. for both of us.

I am wanting to use the 'copy files to one directory' for "personal-professional" use .. I am not gonna distribute it, I can better explain via email ...

The 'recent file on disk' program is just for non-professional personal use .. I will give the data about the settings, when I am home (now at work) .. I can tell I am using country code of Belgium, but using English as language. Will update in other thread ..


0

Response Number 8
Name: Miskva3
Date: January 8, 2003 at 01:20:56 Pacific
Reply:

onefromme2003: I havent got a clue what you are talking about ...

Apart from the assembler code, and the usage of this program, the code is not that difficult ..


0

Response Number 9
Name: Secret_Doom
Date: January 8, 2003 at 09:28:14 Pacific
Reply:

Hello, Miskva.

Miskva wrote:
> but please put the remarks about the
> other program (the one with the 'most
> recent file on disk') in the other
> thread .. Cause it is getting
> complicated .. for both of us.

Ok, I agree. Let's use the other thread. If you prefer, we may use email, instead.

I'll be checking the other thread, as well as my email.

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: copying files to one directory

COPY file to multiple directories www.computing.net/answers/dos/copy-file-to-multiple-directories/14518.html

Bat for copying files www.computing.net/answers/dos/bat-for-copying-files/8872.html

copy files www.computing.net/answers/dos/copy-files-/12140.html