Rename file based on folder name and copy to:

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
LordNecro
Posts: 14
Joined: 18 Apr 2012 03:03

Re: Rename file based on folder name and copy to:

#16 Post by LordNecro » 18 Apr 2012 07:08

the files do not have a system attribute, and while running

Code: Select all

@echo off
for /f "delims=" %%a in ('dir folder.JPG /b /s') do (
for /f "delims=" %%b in ("%%~dpa\.") do (
attrib -h -s "%%a"
copy /b "%%a" "C:\xampp\htdocs\project-T\lists\movies\%%~nxb.JPG"
attrib +h +s "%%a"
)
)
pause


it moves the files, not copies them. luckily yammm remade them.

maybe just a script to make them un hidden, copy/rename and make them hidden again?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Rename file based on folder name and copy to:

#17 Post by foxidrive » 18 Apr 2012 07:46

LordNecro wrote:the files do not have a system attribute, and while running

Code: Select all

@echo off
for /f "delims=" %%a in ('dir folder.JPG /b /s') do (
for /f "delims=" %%b in ("%%~dpa\.") do (
attrib -h -s "%%a"
copy /b "%%a" "C:\xampp\htdocs\project-T\lists\movies\%%~nxb.JPG"
attrib +h +s "%%a"
)
)
pause


it moves the files, not copies them. luckily yammm remade them.

maybe just a script to make them un hidden, copy/rename and make them hidden again?


There are no move commands, or copy and del command, so it can't move them. I suspect you can't see them because they are hidden and maybe system attributes.

What does the attrib command print out, as I mentioned in the previous post?

LordNecro
Posts: 14
Joined: 18 Apr 2012 03:03

Re: Rename file based on folder name and copy to:

#18 Post by LordNecro » 18 Apr 2012 08:01

Code: Select all

C:\Users\Necro>attrib "J:\Movies\12 Monkeys (1995)\folder.jpg"
    H        J:\Movies\12 Monkeys (1995)\folder.jpg

thats the attrib command. i'm not sure what happened earlier, im pretty sure it removed the originals, because i have system files and hidden files visible.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Rename file based on folder name and copy to:

#19 Post by foxidrive » 18 Apr 2012 08:05

Nothing in the batch file could remove the originals.


And your example shows only a HIDDEN attribute so the first batch with attrib should have worked. You said it didn't copy some of the images - which ones didn't it copy? Give a few examples and check the attributes on them.

LordNecro
Posts: 14
Joined: 18 Apr 2012 03:03

Re: Rename file based on folder name and copy to:

#20 Post by LordNecro » 18 Apr 2012 08:26

Code: Select all

@echo off
for /f "delims=" %%a in ('dir folder.JPG /b /s') do (
for /f "delims=" %%b in ("%%~dpa\.") do (
attrib -h "%%a"
copy /b "%%a" "C:\xampp\htdocs\project-T\lists\movies\%%~nxb.JPG"
attrib +h "%%a"
)
)
pause


its not that it doesnt copy some of the files, it gives me a "file not found", meaning it cant find any of the folder.jpg files.


thanks alot for putting up with me and helping with this

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Rename file based on folder name and copy to:

#21 Post by foxidrive » 18 Apr 2012 08:34

Try this: It will pause for every file. Show me a couple of the lines including the pause.

You are running this batch file in J:\movies aren't you?

Code: Select all

@echo off
for /f "delims=" %%a in ('dir folder.JPG /b /s') do (
for /f "delims=" %%b in ("%%~dpa\.") do (
attrib -h "%%a"
echo "%%a"
copy /b "%%a" "C:\xampp\htdocs\project-T\lists\movies\%%~nxb.JPG"
pause
attrib +h "%%a"
)
)
pause

LordNecro
Posts: 14
Joined: 18 Apr 2012 03:03

Re: Rename file based on folder name and copy to:

#22 Post by LordNecro » 18 Apr 2012 08:49

yeah, running it out of he movies folder.

returned with a

Code: Select all

File Not Found
Press any key to continue . . .

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Rename file based on folder name and copy to:

#23 Post by foxidrive » 18 Apr 2012 08:56

Ahh, it's easy to see the issue when you are looking at it.

Try this. It hasn't touched the files at all so far as DIR hasn't returned a list of filenames. That's because they are hidden.

It just needs /a in the DIR command as below.

@echo off
for /f "delims=" %%a in ('dir folder.JPG /a /b /s') do (
for /f "delims=" %%b in ("%%~dpa\.") do (
attrib -h "%%a"
echo "%%a"
copy /b "%%a" "C:\xampp\htdocs\project-T\lists\movies\%%~nxb.JPG"
attrib +h "%%a"
)
)
pause

LordNecro
Posts: 14
Joined: 18 Apr 2012 03:03

Re: Rename file based on folder name and copy to:

#24 Post by LordNecro » 18 Apr 2012 09:05

That's it! awesome man, you just made me a very happy person. Thank you so much.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Rename file based on folder name and copy to:

#25 Post by foxidrive » 18 Apr 2012 09:12

Good one, and you're welcome.

I should have cottoned on to that issue with the DIR command earlier when you said they were hidden but unless you can see the messages returned in the console it can be hard.

So you have all your files, none were deleted. At least not by the batch file.

Post Reply