Computing.Net > Forums > Programming > move files with same name

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

move files with same name

Reply to Message Icon

Name: mii
Date: April 30, 2009 at 09:50:55 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

hi there

i'm only learning to write batches and have a problem with one that i can't get to run as i want it to:

i have 2 folders: C:\Folder1 and C:\Folder2

in Folder1 there is one *.txt and lots of *.pdf-files.

one of all these pdf-files has the same name as the txt-file. (aaa.txt, aaa.pdf, bbb.pdf, ccc.pdf)

all i need to do is move the txt-file (aaa.txt) and the pfd-file with the SAME NAME (in this case aaa.pdf) from Folder1 to the Folder2.

i know the name of the folders, but the name of the files change all the time. how can i handle this?

thank you for any help - it is always greatly apreciated!!!!

;) mii



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: April 30, 2009 at 17:44:32 Pacific
Reply:

:: move pdf w same name as txt

@echo off & setLocal EnableDelayedExpansion

pushd c:\folder1

for /f "tokens=* delims=" %%a in ('dir/b *.txt') do (
move %%a c:\folder2
move %%~Na.pdf c:\folder2
)


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: mii
Date: May 3, 2009 at 13:43:45 Pacific
Reply:

wow. brilliant. thank you very very much for the fast and very useful reply! i really apreciate it a lot!

of course i tried the batch and it works in my test....

but as soon as i put a second *.txt-file into the folder1 it moves that one with the other txt-file. so it would move aaa.txt, aaa.pdf AND xyz.txt. i would only want it to move one txt and one pdf, both with the same name. i tried a few things but nothing worked :(

our situation will be, that we have a bunch of pdf-files in a folder1. then we "generate" txt-files and move them - one by one - to folder1. then they need to be moved with "their" pdf file, two by two, to folder2, so that they both can be imported into an archive at the same time...

hmmm. sorry for the follow-up. maybe you know a solution. if yes, it would be a huge help ;)


0

Response Number 3
Name: Mechanix2Go
Date: May 3, 2009 at 18:48:17 Pacific
Reply:

If there's more than one txt how do you decide which to move?


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 4
Name: mii
Date: May 4, 2009 at 01:06:34 Pacific
Reply:

only the txt-file that has a matching pdf-file - with the exact same name. theoretically it shouldn't happen that there is a txt-file in folder1 without a matching pdf, but if there is an error... it could happen.

so: if folder1 contains

test_1.txt, test_1.pdf, test_2.txt, test_2.pdf, test_3.txt

it should move them all EXCEPT the test_3.txt because that one has no matching pdf. at the moment it would move them all (except the not-matching pdf-files).

i mean, we can use it as it is, but if we could stop the not-matching-txt-files to be moved it would be the deluxe-version ;)


0

Response Number 5
Name: Mechanix2Go
Date: May 4, 2009 at 03:07:29 Pacific
Reply:

@echo off & setLocal EnableDelayedExpansion

pushd c:\folder1

for /f "tokens=* delims=" %%a in ('dir/b *.txt') do (
if exist %%~Na.pdf (
move %%a c:\folder2
move %%~Na.pdf c:\folder2
)
)


=====================================
If at first you don't succeed, you're about average.

M2


0

Related Posts

See More



Response Number 6
Name: mii
Date: May 4, 2009 at 04:59:20 Pacific
Reply:

YEEES, exactly this i was looking for!!! thank you so much! :)


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: move files with same name

batch to move files with same names www.computing.net/answers/programming/batch-to-move-files-with-same-names/19261.html

moving files with a .bat www.computing.net/answers/programming/moving-files-with-a-bat/17109.html

Copy Files to Folder with Same Name www.computing.net/answers/programming/copy-files-to-folder-with-same-name/15568.html