Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to create a .bat file that moves an excel file to specific directory and rename the excel as is the folder name.

UPDATE:

The idea of all this is that I want to copy an file, named below "fisier general.xls" to multiple folders with different names such as "CITY MALL" folder. Now I use the code below, only to copy the file but I realised that the file has to be named exactly as the directory where the excel file was copied in.

copy C:\"Documents and Settings"\rnic\"My Documents"\Razvan\"Rapoarte Aringhe"\"IOAN - Exceptii planograme"\"Fisier general.xls" C:\"Documents and Settings"\rnic\"My Documents"\Razvan\"Rapoarte Aringhe"\"IOAN - Exceptii planograme"\"Mega Image"\"CITY MALL"

maybe you can help me with this.. the fisier general.xls should be renamed as CITY MALL.xls

thanks

share|improve this question
    
Can you elaborate what you're trying to achieve? Initial folder structure and Expected end result folder structure would be nice to have. –  ADTC Aug 22 '13 at 11:08

2 Answers 2

This .bat will go through folders starting with %def% and if there is a file named oldname.xlsx, then it'll move it to first subfolder it finds.

@echo off

set fn=oldname
set ext=.xlsx
set def=c:\

for /R %def% %%i in (.) do ( 
 if exist "%%~di%%~pi%fn%%ext%" (
  for /D %%d in ("%%~di%%~pi*") do (
        move "%%~di%%~pi%fn%%ext%" "%%d\%%~nd%ext%"
  )
 )
)
share|improve this answer
    
hi, the problem is not solved, I don't know how it works, so if you want to help me, here's the code that i use copy C:\"Documents and Settings"\rnic\"My Documents"\Razvan\"Rapoarte Aringhe"\"IOAN - Exceptii planograme"\"Fisier general.xls" C:\"Documents and Settings"\rnic\"My Documents"\Razvan\"Rapoarte Aringhe"\"IOAN - Exceptii planograme"\"Mega Image"\"CITY MALL" maybe you can help me with this.. the fisier general.xls should be renamed as CITY MALL.xls –  Razvan Niculae Aug 22 '13 at 10:56
    
plesase put your code to your question, it is unreadable in the comment box. –  Endoro Aug 23 '13 at 3:59

You don't need as many quotes as you are using in your current batch file.
Also, you can rename the file on the copy command.

copy "C:\Documents and Settings\rnic\My Documents\Razvan\Rapoarte Aringhe\IOAN - Exceptii planograme\Fisier general.xls" "C:\Documents and Settings\rnic\My Documents\Razvan\Rapoarte Aringhe\IOAN - Exceptii planograme\Mega Image\CITY MALL\CITY HALL.xls"

if you wanted this in a batch file where you could supply the file name, I would use make a batch file containing:

copy "C:\Documents and Settings\rnic\My Documents\Razvan\Rapoarte Aringhe\IOAN - Exceptii planograme\Fisier general.xls" "C:\Documents and Settings\rnic\My Documents\Razvan\Rapoarte Aringhe\IOAN - Exceptii planograme\Mega Image\%~1\%~1.xls"

and call the batch file using MyBatchFile "The Folder Name"

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.