• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 754
  • Last Modified:

How to copy files with long filename?

Dear All,

I am trying to copy files which have long filename to a different folder. For eg,

I have a folder which contains,

9291a3264_000.txt
9291a3264_001.txt
9291a3265_000.txt
9291a3265_001.txt

Now, how do i copy all the files with _000.txt to different folder? Any solution help provided with helpful. Thank you in advance.
0
praveenmuppri
Asked:
praveenmuppri
  • 7
  • 4
1 Solution
 
Steve KnightIT ConsultancyCommented:
You can simply do

copy *000.txt c:\wherever

hth

Steve
0
 
Steve KnightIT ConsultancyCommented:
Or even

copy *_000.txt c:\wherever

would be better fitting your question.

You can use * to mean any number of characters and ? to mean one character so you could do

copy ?????????_00t.txt

if you only want ones with 9 characters then _000.txx

Steve
0
 
praveenmuppriAuthor Commented:
Steve, thank you for the reply but i am getting a error message its says "access denied"
0
Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
Steve KnightIT ConsultancyCommented:
OK.... that will be where you are copying them to not having permissions by the sounds of it.  Where are you copying them to?

Try copy *_000.txt "%temp%"

to copy them to your temp drive which you will have rights to, just as a test

Steve
0
 
praveenmuppriAuthor Commented:
Thank you so very much, i think i found what the issue was its fixed now but i have slightly different question now.

I have a folder which contains *_000.txt files and i have a folder which contains *_001.txt files. Now how do i append *_000.txt files with *_001.txt files. For eg,

9291a3264_000.txt should get appended with content of 9291a3264_001.txt. I know we can + to append files but since the file name keep changing how do i run it in batch mode?

Thank you for the help.
0
 
Steve KnightIT ConsultancyCommented:
Believe it or not cmmd prompt will actually do that quite easily.... we can doa  complicated method using getting output of a dir command etc... BUT this will actually work

copy *_000.txt + *_001.txt

Try it on a copy first though, just in case.



Steve
0
 
Steve KnightIT ConsultancyCommented:
followed presumably by a

del *_001.txt to remove the 001 files?
0
 
praveenmuppriAuthor Commented:
Steve, you are a genius. You could even think what needs to be done next. One last question, now that i have one single file with content of both the files how do i remove _000 from the filename. For eg

9291a3264_000.txt will become 9291a3264.txt and 9291a3265_000.txt will become 9291a3265.txt and so on.
0
 
Steve KnightIT ConsultancyCommented:
Ok.  Bit more difficult:

@echo off
rem You can add other stuff here
for /f "tokens=*" %%a in ('dir /b /a-d *_000.txt') do call :renamefile "%%a"
rem And here
goto :eof
rem but not after here.
:renamefile
 set oldname=%~1
 set newname=%oldname:~0,-8%.txt
 echo rename "%oldname%" "%newname%"
goto :eof
rem or after here
0
 
praveenmuppriAuthor Commented:
Excellent solution
0
 
Steve KnightIT ConsultancyCommented:
No problem, glad you liked it!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now