xcopy /l

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
tinfanide
Posts: 117
Joined: 05 Sep 2011 09:15

xcopy /l

#1 Post by tinfanide » 28 Oct 2011 23:10

I've just read the DOS Tip tutorial and am not sure about the use of xcopy /l

Code: Select all

@echo on
for /f %%g in ('xcopy "c:\test\*.*" "d:\test\" /L') do (
   
   if not exist "d:\test\.\%%~nxg" xcopy "%%g" "d:\test\" /p
   
   )
pause


The tutorial says the use of /l is to list the files without actual copying.
But in my codes it does all the copying.
Why?

And,
What's the term of "~nx"?
I can hardly find any help online about the use of "~"?
Can anyone tell me the jargon of the symbol "~" so that I can search the net for some tutorial on it?
Many thanks!

alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

Re: xcopy /l

#2 Post by alan_b » 29 Oct 2011 03:41

tinfanide wrote:

Code: Select all

@echo on
[b]for[/b][size=150][/size] /f %%g in ('xcopy "c:\test\*.*" "d:\test\" /L') do (
   if not exist "d:\test\.\%%~nxg" xcopy "%%g" "d:\test\" /p
   )

What's the term of "~nx"?

The answer is in /?
Do NOT look online - look at your command and append /?

In this case the command is for
So on the command line type FOR /?
You will see about 11 lines above the last of several screens of information
%~nxI - expands %I to a file name and extension only


Your code is unbelievable.
Why do you use xcopy TWICE, and how do you know that the first instance disobeyed the /L option when the second xcopy has been run without ?

I never had problems with xcopy under XP, and I doubt it goes wrong under any other version of Windows.

Nothing surprise me with happens with xcopy ( or any other DOS command )
if the command is wrapped up with the confusion of
FOR %%g in (' any old command and arguments etc.')
My first guess when I fail to get desired results is that my single quotes ' have got the wrong slant or should be double or vice versa.
There are so many ways to do things right, and even more to get them wrong, with this small set of options given by FOR /?
FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]
FOR /F ["options"] %variable IN ("string") DO command [command-parameters]
FOR /F ["options"] %variable IN ('command') DO command [command-parameters]

or, if usebackq option present:

FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]
FOR /F ["options"] %variable IN ('string') DO command [command-parameters]
FOR /F ["options"] %variable IN (`command`) DO command [command-parameters]

In your case I see no reason for the first instance of xcopy,
and there are much simpler ways that WILL provide %%g with every file name to be processed

tinfanide
Posts: 117
Joined: 05 Sep 2011 09:15

Re: xcopy /l

#3 Post by tinfanide » 29 Oct 2011 04:19

alan_b wrote:
tinfanide wrote:

Code: Select all

@echo on
[b]for[/b][size=150][/size] /f %%g in ('xcopy "c:\test\*.*" "d:\test\" /L') do (
   if not exist "d:\test\.\%%~nxg" xcopy "%%g" "d:\test\" /p
   )

What's the term of "~nx"?

The answer is in /?
Do NOT look online - look at your command and append /?

In this case the command is for
So on the command line type FOR /?
You will see about 11 lines above the last of several screens of information
%~nxI - expands %I to a file name and extension only


Your code is unbelievable.
Why do you use xcopy TWICE, and how do you know that the first instance disobeyed the /L option when the second xcopy has been run without ?

I never had problems with xcopy under XP, and I doubt it goes wrong under any other version of Windows.

Nothing surprise me with happens with xcopy ( or any other DOS command )
if the command is wrapped up with the confusion of
FOR %%g in (' any old command and arguments etc.')
My first guess when I fail to get desired results is that my single quotes ' have got the wrong slant or should be double or vice versa.
There are so many ways to do things right, and even more to get them wrong, with this small set of options given by FOR /?
FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]
FOR /F ["options"] %variable IN ("string") DO command [command-parameters]
FOR /F ["options"] %variable IN ('command') DO command [command-parameters]

or, if usebackq option present:

FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]
FOR /F ["options"] %variable IN ('string') DO command [command-parameters]
FOR /F ["options"] %variable IN (`command`) DO command [command-parameters]

In your case I see no reason for the first instance of xcopy,
and there are much simpler ways that WILL provide %%g with every file name to be processed


The unbelievable code is just from the DOS Tip tutorial.
I'm just green in BAT. So don't know what it's going on.

alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

Re: xcopy /l

#4 Post by alan_b » 29 Oct 2011 04:51

Where exactly did you see in DOSTIPS the code
for /f %%g in ('xcopy "c:\test\*.*" "d:\test\" /L')
or even anything resembling
for /f %%? in ('xcopy "???????????" "???????" /L')
Was it here ?
http://www.dostips.com/DtCodeSnippets.p ... SingleLine
or here ?
http://www.dostips.com/DtCodeSnippets.p ... SingleLine

I accept that such code may do something but I would not like to predict what.

I think your line of code would be better replaced with something like
FOR /F %%g in ('DIR "c:\test\*.*" ')
and better still, because it is simpler with less to go wrong
FOR %%g in ("C:\Test\*.*")

tinfanide
Posts: 117
Joined: 05 Sep 2011 09:15

Re: xcopy /l

#5 Post by tinfanide » 29 Oct 2011 05:14

http://www.dostips.com/DtTipsXCopy.php

By the way, could I ask ya where or how ya develop ya own scripting skills?
Is BAT really learnt by looking at the help lines of CMD?
I just find BATCH is even more difficult than any of the scripting languages I've ever learnt, like JS or PHP...

alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

Re: xcopy /l

#6 Post by alan_b » 29 Oct 2011 06:37

Thanks for the link.

O.K. The line is valid but I do not see any benefit over the much simpler
FOR /F %%g in ("c:\test\*.*") do (
and in your case you omitted the argument /Y shown in that link.

In view of this DOSTIP I accept that the weird enclosure of XCOPY within a "FOR IN DO (" context is valid,
so conclude that the unexpected copying of files was entirely due to the second instance of XCOPY.

My first computer had a few hundred bytes of operating system in fixed masked ROM and 128 bytes of RAM.
After soldering 32 off 1024 bit RAM chips plus a fistful of support components I had a 4096 Byte memory card to plug in.
I never had more than 8 of those boards.
An old ASR33 teletypewriter gave output via both printer and Punched Paper Tape,
and accepted input from keyboard and Punched paper Tape.
Input and Output was at 10 characters per second.
Program storage was on Punch Tape at 10 c.p.s = 10 bytes per Second.
Programming was done in Assembler plus bits of binary 01010101 type machine code.
We had books that told us things such as
Jump SubRoutine mnpq = 0xBD mnpq
where mnpq was the 16 bit start address for the subroutine
and an "Assembler" would translate source code JSR into machine code 0xBD

I especially remember filling "unused" RAM with 00111111 so that if the CPU tried to read from where I had not placed instructions,
it would not confuse me by doing wrong things,
instead it would HALT AND CATCH FIRE - the name given for the code known as HCF = 0x3F,
which left the CPU running through the entire memory space reading and doing nothing until a reboot.

When I had my first PC with DOS and Command.com it was wonderful.
I would have much preferred CPM but that was not to be.

I enjoyed invoking a command with /? to find out how to use the command

XP and later now use CMD.EXE which is a little bit different and I always felt to be inferior,
until I came to this forum and found how much better and more powerful.

I can generally cope with most problems by using /?
but there are times (like right now) when I need help from experts here.

I have no experience of JS etc.
I have extensively used ANSI C programming language,
and that is safer then CMD.EXE in that the wrong command aimed at the wrong target with the wrong syntax/arguments may do harm,
whilst similar stupidity in ANSI C will cause no end of warning and errors that need resolving before you can run the code.

tinfanide
Posts: 117
Joined: 05 Sep 2011 09:15

Re: xcopy /l

#7 Post by tinfanide » 29 Oct 2011 07:06

Yes the first instance of xcopy seems to be not helpful. The second one does the job of copying.

It seems that the scripting languages I'm learning now is much evolved from the languages ya learnt some years ago. Different systems and I agree with the thing ya said that errors have to be resolved before running the codes. It seems that JS, PHP is not like that.

I can hardly understand the things ya said about the RAM and CPU things. But I see how ya learnt them. But did ya self-learn them or study at school?

Now I'm only working on my own and have no background of computing. So It's really a hurdle to me. The only place I can resort to is here the experts' help and the /?.

alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

Re: xcopy /l

#8 Post by alan_b » 29 Oct 2011 10:27

Motorola and Intel released 8 bit processors about ten years after I gained an honours B.Sc. in Electronics.
I think this was a little after IBM realised that they could sell more than the two computers they first said would do all the computing the world would ever need.

I had to choose which product my company should consider for incorporating into our Industrial Control products.
A major constraint was a Technical Director who was focussed on quality and reliability at any cost,
because any equipment failure that requires more than 2 fire-brigades to attend to a petro-chemical incident will damage future sales.
He was happy with relays and valves that glow in the dark (and at daytime),
but he wanted transistors to have their legs soldered to the printed circuit board with at least 0.25 inches between them,
and greatly preferred the P.C.B.'s to have copper tracks on only one side.
He would never have permitted any thought of multilayer P.C.B.'s

Getting his approval for integrated circuits with pins at 0.1 inch intervals was going to be extremely difficult,
but I had to prepare for the company's future, and this also prepared me for new opportunities when I had to relocate.

Intel was totally unsuitable with the CPU itself requiring 3 complex chips to be interlinked before connecting any RAM and ROM
Motorola was a clear winner with only a single CPU chip + a clock generator before thinking of RAM and ROM.

I gained all my initial knowledge from Motorola handbooks that detailed :-
the electrical function of each and every one of the 40 pins on the 6800 CPU ; and
the effect of every instruction "op-code" that the CPU was given to obey, and how many CPU cycles it would take.
Apart from the manuals I had to be my own expert.

I achieved a big jump when moving from pure Analogue design work to Digital and Software design.
The state of the art has moved on a tremendous amount.
I am afraid you have a far bigger hurdle to jump now, but there are now experts willing to assist you.
I wish you well.

tinfanide
Posts: 117
Joined: 05 Sep 2011 09:15

Re: xcopy /l

#9 Post by tinfanide » 30 Oct 2011 07:37

Oh, I see. Ya've been learning it at work. Yet, ya were still from Bachelor of Science.
Me totally from an Arts background...
all starting from last a few months...
just fairly recently being into the world of computing and wanting to produce something useful for my own field - education
From learning HTML to PHP, everything was a headache for me
I have been being my own expert and very often go online for some very nice guys' advice
And started wondering how those experts would have known so much in scripting,
cos I just realise I am occassionally very confused with the scripting languages
and most often when I needa debug my codes, I'd really feel the pain
And when I start off learning some of the MS scripting (like BAT, VBS) or Actionscript or Java,
I just see the syntax being discrete, like public or private class never used in Javascript, like delims, tokens as well
thought there's somewhere much the same, like for loop, but it's used in a different logic,
so I just wonder how a developer manages all these, inter-scripting,
does it require a person who has graduated from a college of computer, for instance?

alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

Re: xcopy /l

#10 Post by alan_b » 30 Oct 2011 12:51

About 5 years after I graduated I started having nightmares ;_
I was back in the final exams and faced with exam papers with questions that I recognised from the past,
but 90% of all my knowledge had been totally unused in my work,
so only could only attempt to answer 10% of the papers.

At college we spent half an afternoon using an Analogue oscilloscope to look at the operation of magnetic core memory arrays
http://www.radiomuseum.org/forum/ferrit ... story.html
Apart from that the only Digital education was the use of simple gates to construct a decade counter, e.g.
http://www.tpub.com/neets/book13/55h.htm
Otherwise all electrical theory was Analogue circuits and Analogue Computers.
We also had to suffer lectures by the head of the department on the design of 50 Hz generators that power our kitchens and industry.

I was totally unprepared for the digital world of 8 bit computers.
I could recognise the components and solder them to a P.C.B.,
and cope with the digital circuit design,
but I never had to deal with multi-core 64 bit computers.

By myself without any previous experience or tuition I coped with software Assemblers and 'C' Compilers
I also found BAT to be fun until I used Windows XP and CMD.EXE which is not the same as Command.exe,
but I have learnt a lot more since I found this forum.
VBS is something else.
I am grateful for the VBS code snippets that have been given to me on this forum.

My eldest son was the Captain's Steward in the Royal Navy for many years until he took retirement.
Before his release the Navy paid for a few months I.T. training for his civilian employment,
and he then worked in I.T. support at a college.
He knows his way around modern computers and he can build up a system from basic parts such as Motherboard and SSD/HDD.
He has his own website, and also is I.T. manager for his local Church.
He has a vast range of experience with XP, Vista, Windows 7, and is also into the Windows 8 developer.
He has now become my GOTO GUY if I need a major upgrade/repair.
Not bad for only a few months training in computers.

I would say that designing the next generation of Intel's processors would not be a realistic goal for you,
but doing useful work with software in your field of education is definitely achievable,
and you could do a better job than an existing software professional who is given a requirement specification but does not have your experience with which to understand how the product would actually be applied.

I wish you well in your endeavours

Regards
Alan

tinfanide
Posts: 117
Joined: 05 Sep 2011 09:15

Re: xcopy /l

#11 Post by tinfanide » 31 Oct 2011 03:47

Really thanks for ya sharing... and I realise I've got a better idea of how programming would be like
I wish I'd learnt better of the scripting and designing to improve my field work
:D

alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

Re: xcopy /l

#12 Post by alan_b » 31 Oct 2011 05:40

Since your field is education you may find people who can discuss what you would like to produce,
and advise on relevant languages to learn.
You may also get free or subsidised training.

Caution - try to select and focus on the most useful languages for your immediate future,
otherwise you may often find that you are using the () brackets of one language when writing code for a language that needs {}

Before redundancy I only used BAT files as a hobby with "toy" IBM P.C.'s that BSOD every day.
During redundancy I went on training courses,
learning 'C' during the day and Pascal in the evening, and suffering headaches in the evening.
All three "languages" had conditional statements with similarities that confused me.

Regards
Alan

tinfanide
Posts: 117
Joined: 05 Sep 2011 09:15

Re: xcopy /l

#13 Post by tinfanide » 31 Oct 2011 05:55

I see.
I'm thinking of the languages I should focus on too.
I think I need some more advanced learning on JS, PHP, MySQL coz I need to develop a web platform (not that pro at first I reckon)
But the reason I've been surfing here for BATCH is I need to do some batch stuff on the Windows OS and later on
I need to do some advanced stuff on MS Office
for example,

I need a fixed layout for test papers and let my colleagues enter test data (so that they don't need to worry about the layout and the logic)
The computer will auto check and enter scores onto XLSX spreadsheet.
I know how to do it online (XML-JS-PHP-MySQL) but I think I need to learn Visual Basics or VBA? (Right? Not sure about it)

Thanks in advance for your advice.
This has been really helpful.

alan_b
Expert
Posts: 357
Joined: 04 Oct 2008 09:49

Re: xcopy /l

#14 Post by alan_b » 31 Oct 2011 06:51

I loathe and detest Visual Basic for the traumas inflicted on me by applications created by the incompetent.
Two co-workers each produced a VBA application which the company accepted.

My job required me to use both at different times, and because the co-workers had different platforms ,
I suffered DLL HELL because the "Common DLL's" of one application were not compatible with the other.
This was before XP.
I believe Windows 7 gives "side-by-side" errors instead but have no idea of the consequences.

Perhaps VBA will be good for you now - I just do not know.

I suggest that where you go "online (XML-JS-PHP-MySQL)" may also give you links to helpful communities that can advise which tools they prefer.

Regards
Alan

tinfanide
Posts: 117
Joined: 05 Sep 2011 09:15

Re: xcopy /l

#15 Post by tinfanide » 31 Oct 2011 07:27

Can't imagine ya guys worked so much on pre-XP platforms.
Just cannot imagine the world of that.
I was completely born after the emergence of XP.
Win95, Win98, just alien worlds to me. :P

Yes, going online is just the best way to scripting in addition to reading books or vid tutorials.
Just like me reaching this forum for help on BATCH once I searched the net for BATCH forum.
Really enjoy seeking advice on people who I don't know yet who do care about newbies' enquiries.
Thanks so much. I'm gonna kick off learning some VBA and BATCH for Windows OS first to see if it's suitable for me.

Post Reply