Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Commandline copy with Wildcard mask 2

Status
Not open for further replies.

lameid

Programmer
Jan 31, 2001
4,208
US
I have files named like

longText1.ext
longText2.ext
....


I want to copies like...

longText1VerB.ext
longText2VerB.ext
....

From dos days I expect eh following to work...


Code:
copy *.ext *VerB.ext
What this makes is files named...

longText1.extVerB.ext
longText2.extVerB.ext

So the question is what can I do instead? This seems like it should be really simple.

I did run across but I did not see the solution there but it is at least somewhat illuminating.
 
Look at using XCOPY or Robocopy, both of which are included in windows 7, and have many more switches than just copy.
 
Robocopy won't really help here. Technically it is a tool for copying folders, rather than files. And whilst we can filter the files in a folder that will get copied using wild cards, we cannot rename the files being copied
 
Xcopy has the same behavior as does Rename. I learned command-line stuff with DOS 5.0.
 
> I learned command-line stuff with DOS 5.0.

Please be aware that expansion of wildcard filenames differs slightly between DOS and the NT command line (actually it changed when support for long filenames was introduced, i.e. MSDOS 7). And long filenames introduced their own quirks to the command line utilities.
 
Please be aware that expansion of wildcard filenames differs slightly between DOS and the NT command line (actually it changed when support for long filenames was introduced, i.e. MSDOS 7). And long filenames introduced their own quirks to the command line utilities.

Right... so not knowing the quirks, what is the SOLUTION to my problem... And for clarity Rename, xcopy and copy have the same behavior at NT command line.
 
Well, if all the source files were exactly the same length, ?'s would work, as in below.
copy *.ext ?????????VerB.ext

Not likely that all the source files are the same length though
 
Guitarzan, I think you are telling me the answer is no it can't be done unless the character lengths are fixed.

hairlesssupportmonkey, At a glance that project looks like Synctoy... Or it is for syncing whole folders like robocopy.

Now i'm at least motivated to make a .NET console program (haven't cut my .NET teeth in yet).
 
Key Features

[ul]
[li] Detect moved and renamed files and folders[/li]
[li] Copy locked files (Volume Shadow Copy Service)[/li]
[li] Detect conflicts and propagate deletions[/li]
[li] Binary file comparison[/li]
[li] Full support for Symbolic Links[/li]
[li] Automate sync as a batch job[/li]
[li] Process multiple folder pairs[/li]
[li] Copy NTFS extended attributes (compressed, encrypted, sparse)[/li]
[li] Copy NTFS security permissions[/li]
[li] Support long path names > 260 characters[/li]
[li] Fail-safe file copy[/li]
[li] Comprehensive and detailed error reporting[/li]
[li] Cross-platform: Windows/Linux[/li]
[li] Expand environment variables like %USERPROFILE%[/li]
[li] Access variable drive letters by volume name (USB sticks)[/li]
[li] Native 64-bit support[/li]
[li] Keep versions of deleted/updated files[/li]
[li] Optimal sync sequence prevents disc space bottlenecks[/li]
[li] Full Unicode support[/li]
[li] Highly optimized performance[/li]
[li] Include/exclude files via filter[/li]
[li] FreeFileSync portable and local installation[/li]
[li] Handle daylight saving time changes on FAT/FAT32[/li]
[li] Use macros %time%, %date%, et al. for recurring backups[/li]
[li] Case sensitive synchronization[/li]
[li] Built-in locking serializes multiple jobs running against the same network share[/li]
[/ul]

ACSS - SME
General Geek

 
lameid: No, I'm not saying it can't be done, I'm only saying that having the lengths fixed and using ???'s is the only way I can think of to do it from a command line. I posted it because sometimes partial solutions can prod others to thinking of a better way. But yea, I personally don't see a better command-line way.
 
guitarzan,

Thanks for the input. I was about at the same conclusion.
 
Christ,

I was hoping for a native solution but for actually providing an at least plausible solution to the question have a star!
 
copy longText*.ext longText*VerB.ext

should work.
 
copy longText??.* longText??VerB.*

Use the maximum amount of question marks for your number(s).
The above will change single or double numbers.
 
jkl0,

Thanks for the input but for whatever reason it is changing the numbers masked by the question marks.. So I think I really am at the non-ms solution whether that is third party or make my own.
 
you can use the power of the FOR command

the command would look like this:
for %A in (*.ext) do ren %A %~nAVerA.%~xA

which will take each file, split it into name (%~nA) and extension (%~xA) and put VerA in the middle
(the a part of the %~ comes from the %A used in the for loop)

additional fun, should you wish to look:

You can now use the following optional syntax:

%~I - expands %I removing any surrounding quotes (")
%~fI - expands %I to a fully qualified path name
%~dI - expands %I to a drive letter only
%~pI - expands %I to a path only
%~nI - expands %I to a file name only
%~xI - expands %I to a file extension only
%~sI - expanded path contains short names only
%~aI - expands %I to file attributes of file
%~tI - expands %I to date/time of file
%~zI - expands %I to size of file
%~$PATH:I - searches the directories listed in the PATH environment variable and expands %I to the fully qualified name of the first one found. If the environment variable name is not defined or the file is not found by the search, then this modifier expands to the empty string
%~zI - expands %I to size of file
%~$PATH:I - searches the directories listed in the PATH environment variable and expands %I to the fully qualified name of the first one found. If the environment variable name is not defined or the file is not found by the search, then this modifier expands to the empty string

The modifiers can be combined to get compound results:

%~dpI - expands %I to a drive letter and path only
%~nxI - expands %I to a file name and extension only
%~fsI - expands %I to a full path name with short names only
%~dp$PATH:I - searches the directories listed in the PATH environment variable for %I and expands to the drive letter and path of the first one found.
%~ftzaI - expands %I to a DIR like output line
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top