1.

Solve : Append name of parent folders to the names of the files?

Answer»

Dias DE verano wrote:

"If the original filename had any spaces in it it would fail."

Bill writes:

We solved that problem by using "" quotes around the old file name and the new file name. For example: ren "%%a" "2009.January.%%a"
output:
08/04/2004 07:00 AM 81,433 2009.January.Red moon desert.jpg
Thanks for your help.


C:\>type renamejpg.bat
@echo off

Rem run this batch file with 3 command line variables
REM renamejpg.bat c:\new jpg 2009.January

REM renamejpg.bat destination extension Portion of file name

setlocal

REM Copy *.%2 %1
Rem Must be in the directory where files are originally

cd %1

for /f "tokens=*" %%a in ('dir /b *.%2') do ren "%%a" "%3.%%a"

C:\>renamejpg.bat c:\new jpg 2009.January


C:\>cd new
C:\new>dir *.jpg

Volume Serial Number is B8F2-4B99

Directory of C:\new


09/24/2008 09:07 PM 22,033 2009.January.piper.jpg
08/04/2004 07:00 AM 57,925 2009.January.Purple flower.jpg
08/04/2004 07:00 AM 44,190 2009.January.Radiance.jpg
08/04/2004 07:00 AM 81,433 2009.January.Red moon desert.jpg
12/03/2008 07:07 PM 58,551 2009.January.redflower.jpg
05/08/2008 07:47 PM 63,784 2009.January.Slide2.jpg
05/08/2008 07:48 PM 41,097 2009.January.Slide4.jpg
05/09/2008 07:10 AM 42,105 2009.January.Slide6.jpg
05/09/2008 07:11 AM 51,122 2009.January.Slide8.jpg
05/09/2008 07:12 AM 55,696 2009.January.Slide9.jpg
08/04/2004 07:00 AM 73,159 2009.January.Tulips.jpg
08/04/2004 07:00 AM 37,246 2009.January.Wind.jpg
08/22/2008 10:17 AM 8,165 2009.January.wolf3.jpg
31 File(s) 2,169,842 bytes


C:\new>suppose the path isn't 2009\January?
Regarding spaces, I was thinking about the lack of a delims block, but the tokens=* fixed that. Plus the quotes of course.

Without wanting to seem vain, I did already post a working example which answers the OP's request, (to copy a file to a folder and automatically name the copy with the elements of its previous path). Billrich STILL hasn't done that.

And the OP wants to copy the file to a folder and give it a new name, not rename it in place. (read the original post).


Additionally it would be far easier to read if somebody would use code tags...Bc,


Information that is not needed by BC or Dias de verano might be be useful to new people. I will erase almost all my posts. If any of the remaining posts harm the Board, feel free to erase the remaining posts also.

Good Luck with HELPING people. There is not much feedback. Maybe no feedback means the board helped somebody?billrich, why are you wasting all our time?
Quote

Bc,
From for /? at command prompt.


I fail to see what that has to do with my post, but alright.

This thread has really degenerated.
Bc,

I'm trying to learn how to use the for loop. I have not seen any for loops from BC. I appreciate your help.

BC had suggested more tags and information about the for loop so I suggested the for /? at command prompt.

I TRY to be nice and I still receive many negative comments. My "for loop" was an excellent solution to the the copy and rename file names problem.

What should I do to remain on this board?

What does BC, Carbon and Dias de verano want me do?

I feel you do not want to help me. Are my posts really that bad?

Why is Dias de verano so cruel to new people?

Do you want me to leave?



From for /? at command prompt.

Runs a specified command for each file in a set of files.Quote
I try to be nice

You hijacked another person's thread and made it about "you" and made many trollish posts.Code: [Select][quote author=billrich link=topic=78827.msg521043#msg521043 date=1237249761]
BC had suggested more tags and information about the for loop so I suggested the for /? at command prompt.
[/quote]

That had absolutely nothing to do with what I meant.


I meant, instead of all this:

[quote author=billrich link=topic=78827.msg520596#msg520596 date=1237199880]
C:\>type renamejpg.bat
@echo off

Rem run this batch file with 3 command line variables
REM renamejpg.bat c:\new jpg 2009.January

REM renamejpg.bat destination extension Portion of file name

setlocal

REM Copy *.%2 %1
Rem Must be in the directory where files are originally

cd %1

for /f "tokens=*" %%a in ('dir /b *.%2') do ren "%%a" "%3.%%a"

C:\>renamejpg.bat c:\new jpg 2009.January


C:\>cd new
C:\new>dir *.jpg

Volume Serial Number is B8F2-4B99

Directory of C:\new


09/24/2008 09:07 PM 22,033 2009.January.piper.jpg
[b]08/04/2004 07:00 AM 57,925 2009.January.Purple flower.jpg[/b]
08/04/2004 07:00 AM 44,190 2009.January.Radiance.jpg
[b]08/04/2004 07:00 AM 81,433 2009.January.Red moon desert.jpg[/b]
12/03/2008 07:07 PM 58,551 2009.January.redflower.jpg
05/08/2008 07:47 PM 63,784 2009.January.Slide2.jpg
05/08/2008 07:48 PM 41,097 2009.January.Slide4.jpg
05/09/2008 07:10 AM 42,105 2009.January.Slide6.jpg
05/09/2008 07:11 AM 51,122 2009.January.Slide8.jpg
05/09/2008 07:12 AM 55,696 2009.January.Slide9.jpg
08/04/2004 07:00 AM 73,159 2009.January.Tulips.jpg
08/04/2004 07:00 AM 37,246 2009.January.Wind.jpg
08/22/2008 10:17 AM 8,165 2009.January.wolf3.jpg
31 File(s) 2,169,842 bytes


C:\new>
[/quote]

use this:

[code]
@echo off

Rem run this batch file with 3 command line variables
REM renamejpg.bat c:\new jpg 2009.January

REM renamejpg.bat destination extension Portion of file name

setlocal

REM Copy *.%2 %1
Rem Must be in the directory where files are originally

cd %1

for /f "tokens=*" %%a in ('dir /b *.%2') do ren "%%a" "%3.%%a"

IE a code tag; the forum has a lot of useful bbcode tags that work wonderfully.


Quote

I'm trying to learn how to use the for loop. I have not seen any for loops from BC. I appreciate your help.


isn't two Do...Loops Enough?



regardless of which, I'm not particularly good with the new command line extensions; I stopped using batch programming extensively before I switched from windows 3.1, so I haven't really researched all the new stuff that can be done with it. I can use For quite well for it's original specs, but I haven't had time to sufficiently learn the new nuances added with CMD.

I have however learned not to say stuff is impossible in batch, because the MOMENT I say that, and provide a VBScript solution Dias has a much shorter Batch program that does the same thing ... and even with VBScript I keep trying to use left$ Right$ Mid$ etc, when in fact VBScript has no notion of any type other then variant, and thus there is no $ suffix on any string manipulation functions. I still type them instinctively so I have to always check over my VBScript to make sure that I didn't let some money sneak in


The fact of the matter is- this thread was solved when Dias posted his batch. your post could only suffice to confuse the OP since- as explained - it merely illustrated the REN command.[/code]


Discussion

No Comment Found