Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Append name of parent folders to the names of the files  (Read 11418 times)

0 Members and 1 Guest are viewing this topic.

observer

  • Guest
Append name of parent folders to the names of the files
« on: March 13, 2009, 11:16:41 AM »
I need help in appending  name of parent folders and Subfolders to the name of the files


OS: Windows XP SP2
Files are stored as shown in Example:C:\2009\January\photo.jpg
                                                                                       Tata.jpg
                                                                                       Nato.jpg

I would like to copy these files in

C:\New

 as         2009.January.photo.jpg
             2009.January.Tata.jpg
             2009.January.Nato.jpg


or 2009-January-photo.jpg

Thanks.
« Last Edit: March 13, 2009, 11:43:27 AM by observer »

Dias de verano

  • Guest
Re: Append name of parent folders to the names of the files
« Reply #1 on: March 13, 2009, 01:20:23 PM »
Remove "echo" when you are satisfied it works.

Remove / add REM to choose separator character (others are possible although some chars are illegal)

Code: [Select]
@echo off
setlocal enabledelayedexpansion
set srcfolder=C:\2009\January\
set dstfolder=C:\New\
REM set separator=~
REM set separator=-
set separator=.
cd /d %srcfolder%
for /f "delims==" %%F in ( ' dir /b *.jpg ' ) do (
   set srcfile=%%~dpnxF
   set dstfile=%%~pnxF
   call set dstfile=!dstfile:\=%%separator%%!
   set dstfile=!dstfile:~1!
   echo Copy "!srcfile!" "%dstfolder%!dstfile!"
   )

« Last Edit: March 13, 2009, 02:24:47 PM by Dias de verano »

billrich

  • Guest
Re: Append name of parent folders to the names of the files
« Reply #2 on: March 13, 2009, 05:01:40 PM »
Observer,


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>
« Last Edit: March 16, 2009, 07:16:06 PM by billrich »

Dias de verano

  • Guest
Re: Append name of parent folders to the names of the files
« Reply #3 on: March 13, 2009, 05:22:20 PM »
C:\>echo tata.jpg >> Tata.jpg

That is just crazy. I suggest you read the original post again. And only post when you actually know the answer.

« Last Edit: March 13, 2009, 05:37:12 PM by Dias de verano »

billrich

  • Guest
Re: Append name of parent folders to the names of the files
« Reply #4 on: March 13, 2009, 09:29:08 PM »
My remarks were rude and unneccesary.

I apologize  to everyone.
« Last Edit: March 15, 2009, 09:10:47 PM by billrich »

Dias de verano

  • Guest
Re: Append name of parent folders to the names of the files
« Reply #5 on: March 14, 2009, 02:01:01 AM »
Billrich, you are full of it.

1. OP wrote "I would like to copy these files."

2. echo abc.jpg >> Abc.jpg is just plain stupid, and if you can't see why, maybe you should not be posting in this forum?

3.

Quote
p.s The " echo tata.jpg >> Tata.jpg  is a quick way to create a file with  the Tata.jpg name

But the file already exists. It is an image file. How is appending some text to it going to help anything? (Windows command is case insensitive, so tata.jpg and Tata.jpg are the same file.)

Like I said, full of it.

billrich

  • Guest
Re: Append name of parent folders to the names of the files
« Reply #6 on: March 14, 2009, 06:01:50 AM »
 My remarks were rude and unnecessary.

I apologize  to everyone.
« Last Edit: March 15, 2009, 09:22:17 PM by billrich »

Dias de verano

  • Guest
Re: Append name of parent folders to the names of the files
« Reply #7 on: March 14, 2009, 06:28:18 AM »
all that is needed is the rename command.

The OP wants to copy, not rename.

Carbon Dudeoxide

  • Global Moderator

  • Mastermind
  • Thanked: 169
    • Yes
    • Yes
    • Yes
  • Certifications: List
  • Experience: Guru
  • OS: Mac OS
Re: Append name of parent folders to the names of the files
« Reply #8 on: March 14, 2009, 06:32:05 AM »
Carbon Says: LOL

billrich

  • Guest
Re: Append name of parent folders to the names of the files
« Reply #9 on: March 14, 2009, 07:11:48 AM »
 My remarks were rude and unnecessary.

I apologize  to everyone.
« Last Edit: March 15, 2009, 09:23:04 PM by billrich »

Dias de verano

  • Guest
Re: Append name of parent folders to the names of the files
« Reply #10 on: March 14, 2009, 07:18:02 AM »
Maybe if you devoted more time to learning some scripting, and less to making pretty colored posts?

harry 48



    Egghead

  • lay back , relax and chill out
  • Thanked: 129
    • Yes
    • Yes
    • Yes
    • Dribbling Pensioner
  • Certifications: List
  • Experience: Familiar
  • OS: Windows 7
Re: Append name of parent folders to the names of the files
« Reply #11 on: March 14, 2009, 07:47:35 AM »
children , children , you are getting no-where at this rate , harry

Carbon Dudeoxide

  • Global Moderator

  • Mastermind
  • Thanked: 169
    • Yes
    • Yes
    • Yes
  • Certifications: List
  • Experience: Guru
  • OS: Mac OS
Re: Append name of parent folders to the names of the files
« Reply #12 on: March 14, 2009, 08:39:25 AM »
observer wrote
 
"I need help in renaming  appending  name of parent folders and Subfolders to the
name of the files


No he didn't. Where in Observer's post did he say the word 'renaming'?

I need help in appending  name of parent folders and Subfolders to the name of the files

Seems to me you randomly added the word, Billrich.

billrich

  • Guest
Re: Append name of parent folders to the names of the files
« Reply #13 on: March 14, 2009, 10:00:05 AM »
 My remarks were rude and unnecessary.

I apologize  to everyone.
« Last Edit: March 15, 2009, 09:23:46 PM by billrich »

Dias de verano

  • Guest
Re: Append name of parent folders to the names of the files
« Reply #14 on: March 14, 2009, 10:37:54 AM »
Billrich being a jerk.