Too much path in path

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
 
May 29, 2008
37
0
Medway, Mass.
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
 
May 20, 2008
11,285
95
Syracuse, NY, USA
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).
 
May 29, 2008
37
0
Medway, Mass.
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
 
May 29, 2008
37
0
Medway, Mass.
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
 
May 20, 2008
3,515
4
Elkridge, MD, USA
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
 
May 20, 2008
3,515
4
Elkridge, MD, USA
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
 
May 20, 2008
3,515
4
Elkridge, MD, USA
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
Thread starter Title Forum Replies Date
Jay Sage Take Command Is Too Fast! Support 4
H Beta - DEDUPE /P - Too many prompts Support 0
N Popup Window size too small Support 5
E TCC History popups too small Support 0
M Question about the "Start" command that is admittedly not too important and just out of curiosity... Support 1
M An issue I really don't understand and is too long and detailed for this "Title" line... Support 16
S TCC's OPTION dialog too large Support 1
D TCC has much more elegant ways for usebackq. What ways? Support 12
T TCv9.0 much slower than TCI v2.0/4NT Support 8
V Set path permanently from within TCC? Support 3
Jay Sage Command Will Not Run Using Short Name of Path Support 5
Joe Caverly PUSHD with UNC path in CMD.EXE Support 2
MickeyF Why doesn't my python program get executed without specifying its path? Support 2
M How to set Path variable for non-executable file extensions in 4DOS Support 8
D How to? Path problems in TCC20 Support 1
vefatica "COMSPEC path" Support 2
Patulus TCHistoryLog: TCC: (Sys) The system cannot find the path specified Support 15
vefatica If there's no PATH variable ... Support 5
D V19: toolbar /r "path\tctoolbar.ini" Support 1
C ECHOing the _CWD with a & in the path Support 7
David McClelland How to? Path Changes Support 4
gschizas Fixed Cannot use extended path to delete invalid file Support 3
nickles Fixed In batch files, %0 now evaluates to the absolute path Support 9
cgunhouse IFTP Path Issue in V17 - Fixed Support 7
M How to? List path getting short file and directory names... Support 10
M How to? Get both path to and target of symbolic link/junction... Support 2
N Command completion and PATH Support 0
noahcoad How to? Create shortcut with env var in path Support 4
Exolon Space within path and FOR Support 4
A WAD Dir daterange + multiple path wildcards crashes tcc Support 2
D TCC can't start app if @shfolder[42] used for path Support 1
fpefpe How to? Path(s) for Python Support 0
D TPIPE works without being in path, but not V; aemail Support 8
Stefano Piccardi IDE.exe start toobar button fails when % in script path Support 0
H 12.10 UNZIP ignores destination path spec Support 2
Phileosophos unzip not using specified path Support 5
D Extracting the current command line, extracting current path Support 4
Stefano Piccardi char class wildcard issue when [] in path Support 14
D Function to see if a UNC path is mapped? Support 9
williamleara Specifying path to TCMD.INI causes issues Support 8
hrensink Path length limit Support 9
CWBillow Adding to the path Support 6
D D:\Settings\Application contains an incorrect path? Support 0
M TCC cannot find the path specified Support 4

Similar threads