Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Too much path in path

Jul
33
0
Hi,
Well, I couldn't do it in a "for" loop, so, now I'm trying it in a batch file using "do." Here's my script.

L:
cd pdf\single\misc
do ehsfile in "::[A-z]{1}[0-9]{7}.pdf"
copy %ehsfile L:\pdf\single\misc\ehs-%ehsfile
enddo
c:

And, here's what I'm getting.

copy L:\pdf\single\misc\a1203001.pdf ehs-L:\pdf\single\misc\a1203001.pdf

What's up with this? I obviously don't want the full path prefixed with the "ehs-," only the filename itself. I tried "copy %ehsfile ehs-%ehsfile," too, but, I got the same thing.

Can anyone help?

Thanks,
Peter
 
Check out the %@Name[] function.



Mr.Jiggs
pb4072 wrote:




Hi,
Well, I couldn't do it in a "for" loop, so, now I'm trying it in a
batch file using "do." Here's my script.

L:
cd pdf\single\misc
do ehsfile in "::[A-z]{1}[0-9]{7}.pdf"
copy %ehsfile L:\pdf\single\misc\ehs-%ehsfile
enddo
c:

And, here's what I'm getting.

copy L:\pdf\single\misc\a1203001.pdf ehs-L:\pdf\single\misc\a1203001.pdf

What's up with this? I obviously don't want the full path prefixed with
the "ehs-," only the filename itself. I tried "copy %ehsfile
ehs-%ehsfile," too, but, I got the same thing.

Can anyone help?

Thanks,
Peter
 
On Mon, 28 Jul 2008 08:07:23 -0500, pb4072 <> wrote:


>L:
>cd pdf\single\misc
>do ehsfile in "::[A-z]{1}[0-9]{7}.pdf"
> copy %ehsfile L:\pdf\single\misc\ehs-%ehsfile
>enddo
>c:
>
>And, here's what I'm getting.
>
>copy L:\pdf\single\misc\a1203001.pdf ehs-L:\pdf\single\misc\a1203001.pdf
>
>What's up with this? I obviously don't want the full path prefixed with the "ehs-," only the filename itself. I tried "copy %ehsfile ehs-%ehsfile," too, but, I got the same thing.

I don't know why REs result in fully-qualified paths; wildcards don't.

I suppose you could

copy %ehsfile L:\pdf\single\misc\ehs-%@filename[%ehsfile]

(or something like that).
 
Check out the %@Name[] function.



Mr.Jiggs
pb4072 wrote:




Hi,
Well, I couldn't do it in a "for" loop, so, now I'm trying it in a
batch file using "do." Here's my script.

L:
cd pdf\single\misc
do ehsfile in "::[A-z]{1}[0-9]{7}.pdf"
copy %ehsfile L:\pdf\single\misc\ehs-%ehsfile
enddo
c:

And, here's what I'm getting.

copy L:\pdf\single\misc\a1203001.pdf ehs-L:\pdf\single\misc\a1203001.pdf

What's up with this? I obviously don't want the full path prefixed with
the "ehs-," only the filename itself. I tried "copy %ehsfile
ehs-%ehsfile," too, but, I got the same thing.

Can anyone help?

Thanks,
Peter
 
That worked! Thank you.

Check out the %@Name[] function.



Mr.Jiggs
pb4072 wrote:




Hi,
Well, I couldn't do it in a "for" loop, so, now I'm trying it in a
batch file using "do." Here's my script.

L:
cd pdf\single\misc
do ehsfile in "::[A-z]{1}[0-9]{7}.pdf"
copy %ehsfile L:\pdf\single\misc\ehs-%ehsfile
enddo
c:

And, here's what I'm getting.

copy L:\pdf\single\misc\a1203001.pdf ehs-L:\pdf\single\misc\a1203001.pdf

What's up with this? I obviously don't want the full path prefixed with
the "ehs-," only the filename itself. I tried "copy %ehsfile
ehs-%ehsfile," too, but, I got the same thing.

Can anyone help?

Thanks,
Peter
 
OK. Well, Mr. Jiggs' idea worked, but, I'm getting serious repetitions here.
Here's my script:

do ehsfile in "::[A-z]{1}[0-9]{7}.pdf"
copy %ehsfile ehs-%@Name[%ehsfile].pdf && copy %ehsfile L:\pdf\single\ehs\fedtables\ehs-%@Name[%ehsfile].pdf
enddo

I'm ending up with files beginning with "ehs-," but, I'm also ending up with files beginning with "ehs-ehs," "ehs-ehs-ehs," "ehs-ehs-ehs-ehs," and so on . . . !


Hi,
Well, I couldn't do it in a "for" loop, so, now I'm trying it in a batch file using "do." Here's my script.

L:
cd pdf\single\misc
do ehsfile in "::[A-z]{1}[0-9]{7}.pdf"
copy %ehsfile L:\pdf\single\misc\ehs-%ehsfile
enddo
c:

And, here's what I'm getting.

copy L:\pdf\single\misc\a1203001.pdf ehs-L:\pdf\single\misc\a1203001.pdf

What's up with this? I obviously don't want the full path prefixed with the "ehs-," only the filename itself. I tried "copy %ehsfile ehs-%ehsfile," too, but, I got the same thing.

Can anyone help?

Thanks,
Peter
 
It's been a while since I've used it, but you need
to add an "exclusion" so that files of the format "ehs-*.pdf" are not
copied…



Mr. Jiggs


pb4072 wrote:




OK. Well, Mr. Jiggs' idea worked, but, I'm getting
serious repetitions here.
Here's my script:

do ehsfile in "::[A-z]{1}[0-9]{7}.pdf"
copy %ehsfile ehs-%@Name[%ehsfile].pdf && copy %ehsfile
L:\pdf\single\ehs\fedtables\ehs-%@Name[%ehsfile].pdf
enddo

I'm ending up with files beginning with "ehs-," but, I'm also ending up
with files beginning with "ehs-ehs," "ehs-ehs-ehs," "ehs-ehs-ehs-ehs,"
and so on . . . !



Quote:




Originally Posted by pb4072
Hi,
Well, I couldn't do it in a "for" loop, so, now I'm trying it in a
batch file using "do." Here's my script.

L:
cd pdf\single\misc
do ehsfile in "::[A-z]{1}[0-9]{7}.pdf"
copy %ehsfile L:\pdf\single\misc\ehs-%ehsfile
enddo
c:

And, here's what I'm getting.

copy L:\pdf\single\misc\a1203001.pdf ehs-L:\pdf\single\misc\a1203001.pdf

What's up with this? I obviously don't want the full path prefixed with
the "ehs-," only the filename itself. I tried "copy %ehsfile
ehs-%ehsfile," too, but, I got the same thing.

Can anyone help?

Thanks,
Peter
 
pb4072 wrote:
| OK. Well, Mr. Jiggs' idea worked, but, I'm getting serious
| repetitions here.
| Here's my script:
|
| do ehsfile in "::[A-z]{1}[0-9]{7}.pdf"
| copy %ehsfile ehs-%@Name[%ehsfile].pdf && copy %ehsfile
| L:\pdf\single\ehs\fedtables\ehs-%@Name[%ehsfile].pdf
| enddo
|
| I'm ending up with files beginning with "ehs-," but, I'm also ending
| up with files beginning with "ehs-ehs," "ehs-ehs-ehs,"
| "ehs-ehs-ehs-ehs," and so on . . . !

You made a common mistake. Your source and target directories are the same,
and the target names qualify as source names. As a result, the target files,
which have just been created, qualify as source files, and are copied again,
and again, and again, ...

When an overlap between source and target set is possible, the only safe way
to operate is to list the true source set, and operate on each set member
without regenerating the set. The most common method to do this for file
sets is using DIR to create the source list, and piping it to the action
command:

Line 1: *cdd L:\pdf\single\misc
Line 2: dir/b "::[A-z]{1}[0-9]{7}.pdf" | for %f in (@con:) (copy %f ehs-%f
&& copy %f ..\ehs\fedtables\ehs-%f)
Line 3: C:

NOTE: Why do you need to make a copy of each source file in the source
directory, with the new name? Your original program did not do that, it just
copied the files with the new name into the target directory.

WARNINGS:
1/ While the method is well tested, the actual commands above are untested.
2/ The copying with the new names into the source directory prevents
repeating the program without directory cleanup, as repeated use will
duplicate the files created the first time.
--
HTH, Steve
 
OK. Thanks a lot. Yes, I am copying to two places. The source directory, and, another sister directory. I need it in the source for other peoples' scripts in my company. I've resolved it by simply sending it to the second directory, only. Then, once done, I'll simply copy from there back to the source.

Thanks again.

Peter


pb4072 wrote:
| OK. Well, Mr. Jiggs' idea worked, but, I'm getting serious
| repetitions here.
| Here's my script:
|
| do ehsfile in "::[A-z]{1}[0-9]{7}.pdf"
| copy %ehsfile ehs-%@Name[%ehsfile].pdf && copy %ehsfile
| L:\pdf\single\ehs\fedtables\ehs-%@Name[%ehsfile].pdf
| enddo
|
| I'm ending up with files beginning with "ehs-," but, I'm also ending
| up with files beginning with "ehs-ehs," "ehs-ehs-ehs,"
| "ehs-ehs-ehs-ehs," and so on . . . !

You made a common mistake. Your source and target directories are the same,
and the target names qualify as source names. As a result, the target files,
which have just been created, qualify as source files, and are copied again,
and again, and again, ...

When an overlap between source and target set is possible, the only safe way
to operate is to list the true source set, and operate on each set member
without regenerating the set. The most common method to do this for file
sets is using DIR to create the source list, and piping it to the action
command:

Line 1: *cdd L:\pdf\single\misc
Line 2: dir/b "::[A-z]{1}[0-9]{7}.pdf" | for %f in (@con:) (copy %f ehs-%f
&& copy %f ..\ehs\fedtables\ehs-%f)
Line 3: C:

NOTE: Why do you need to make a copy of each source file in the source
directory, with the new name? Your original program did not do that, it just
copied the files with the new name into the target directory.

WARNINGS:
1/ While the method is well tested, the actual commands above are untested.
2/ The copying with the new names into the source directory prevents
repeating the program without directory cleanup, as repeated use will
duplicate the files created the first time.
--
HTH, Steve
 
Turns out this doesn't work either, Steve. I get the same results, with repetitions of filenames.


pb4072 wrote:
| OK. Well, Mr. Jiggs' idea worked, but, I'm getting serious
| repetitions here.
| Here's my script:
|
| do ehsfile in "::[A-z]{1}[0-9]{7}.pdf"
| copy %ehsfile ehs-%@Name[%ehsfile].pdf && copy %ehsfile
| L:\pdf\single\ehs\fedtables\ehs-%@Name[%ehsfile].pdf
| enddo
|
| I'm ending up with files beginning with "ehs-," but, I'm also ending
| up with files beginning with "ehs-ehs," "ehs-ehs-ehs,"
| "ehs-ehs-ehs-ehs," and so on . . . !

You made a common mistake. Your source and target directories are the same,
and the target names qualify as source names. As a result, the target files,
which have just been created, qualify as source files, and are copied again,
and again, and again, ...

When an overlap between source and target set is possible, the only safe way
to operate is to list the true source set, and operate on each set member
without regenerating the set. The most common method to do this for file
sets is using DIR to create the source list, and piping it to the action
command:

Line 1: *cdd L:\pdf\single\misc
Line 2: dir/b "::[A-z]{1}[0-9]{7}.pdf" | for %f in (@con:) (copy %f ehs-%f
&& copy %f ..\ehs\fedtables\ehs-%f)
Line 3: C:

NOTE: Why do you need to make a copy of each source file in the source
directory, with the new name? Your original program did not do that, it just
copied the files with the new name into the target directory.

WARNINGS:
1/ While the method is well tested, the actual commands above are untested.
2/ The copying with the new names into the source directory prevents
repeating the program without directory cleanup, as repeated use will
duplicate the files created the first time.
--
HTH, Steve
 
pb4072 wrote:
| Turns out this doesn't work either, Steve. I get the same results,
| with repetitions of filenames.

Is this after you cleaned up from your previous runs, which created from
XXX.pdf first ehs-XXX.pdf, then ehs-ehs-XXX.pdf, then ehs-ehs-ehs-XXX.pdf,
then ehs-ehs-ehs-ehs-XXX.pdf, then ehs-ehs-ehs-ehs-ehs-XXX.pdf, etc.?

In general, when testing a file manipulation program, it is best to make a
copy of the source and target directories before doing anything else under
temporary names. Before a 2nd or subsequent test empty both source and
target directories, and copy the saved files into them. Now you have a
known, repeatable starting configuration.

I never had problems with piping from DIR including files created by the
piped-to command.
--
Steve
 
No, I'd already cleaned out the directories of all "ehs" files. I ran it again just to one directory. I'll copy them later. But, why doesn't my regex work right? I'm using the following and it's picking up files that begin with two letters.

dir/b "::^[A-z]{1}[0-9]{7}.pdf" | for %f in (@con) copy %f ehs-%f

It's picking up files like "ee1234567.pdf."



pb4072 wrote:
| Turns out this doesn't work either, Steve. I get the same results,
| with repetitions of filenames.

Is this after you cleaned up from your previous runs, which created from
XXX.pdf first ehs-XXX.pdf, then ehs-ehs-XXX.pdf, then ehs-ehs-ehs-XXX.pdf,
then ehs-ehs-ehs-ehs-XXX.pdf, then ehs-ehs-ehs-ehs-ehs-XXX.pdf, etc.?

In general, when testing a file manipulation program, it is best to make a
copy of the source and target directories before doing anything else under
temporary names. Before a 2nd or subsequent test empty both source and
target directories, and copy the saved files into them. Now you have a
known, repeatable starting configuration.

I never had problems with piping from DIR including files created by the
piped-to command.
--
Steve
 
pb4072 wrote:
| No, I'd already cleaned out the directories of all "ehs" files. I ran
| it again just to one directory. I'll copy them later. But, why
| doesn't my regex work right? I'm using the following and it's picking
| up files that begin with two letters.
|
| dir/b "::^[A-z]{1}[0-9]{7}.pdf" | for %f in (@con) copy %f ehs-%f
|
| It's picking up files like "ee1234567.pdf."

I've not used the regular expressions inside TCC, except for a few tests
when they were first introduced. However, from my experience with them in
other contexts the {1} looks at least superfluous - why use a repetition
factor for an expression that's not repeated? According to the description
in HELP topic "regularexpressionsyntax.htm" for Ruby regex-es it ought to be
harmless.

Another point is [A-z] - that character set includes non-alphabetic
characters. Which characters depends on the character encoding in effect at
the time: ASCII v. Unicode. Since filename matches are always case
insensitive, you could use [a-z] which is guaranteed to include only the 26
letters of the English alphabet, regardless of encoding. You could also use
the special representation for "alphabetic character", and the one for
decimal digits instead of [0-9].

BTW, you could use the less elegant but easier to understand extended
wildcard syntax:

dir/b [a-z][0-9][0-9][0-9][0-9][0-9][0-9][0-9].pdf" | for %f in (@con) copy
%f ehs-%f

or its single-process variant:

for %f in ([a-z][0-9][0-9][0-9][0-9][0-9][0-9][0-9].pdf) copy %f ehs-%f

Regardless, I do not like the idea of copying files into the same directory.
It's just too easy to create copies that are picked up as if they were new
files.

BTW, why do you need copies of the files, with new name, in the same
directory? If the purpose is anything other than modifying one of them in
place, AND if your drive is NTFS, you can use the MKLNK command to just
create additional directory entries for each file, which is much faster as
well as using less disk space.
--
HTH, Steve
 

Similar threads

Back
Top