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.
praveenmuppriAsked:
Who is Participating?
 
Steve KnightConnect With a Mentor IT 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
 
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
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
praveenmuppriAuthor Commented:
Steve, thank you for the reply but i am getting a error message its says "access denied"
0
 
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
 
praveenmuppriAuthor Commented:
Excellent solution
0
 
Steve KnightIT ConsultancyCommented:
No problem, glad you liked it!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.