0

I want to copy the files from current folder to another location like (CURRENT FOLDER) file name like this (F0#CGDBANG000947532#) to another location like (\10.10.10.1\BasketsIn) with user name in the file name like (F0#CGDBANG000947532#logesh) at the end F0#CGDBANG000947532# copy to F0#CGDBANG000947532#username

thanks

Logesh
  • 21
  • 1
  • 8
  • Could you provide a little more detail? Are you just trying to copy one file? Or a whole set of files? – lurker May 24 '14 at 12:15
  • Your question is unclear! – ρss May 24 '14 at 12:26
  • I want to copy the files in current folder to another location like (CURRENT FOLDER) file name like this (F0#CGDBANG000947532#) to another location like (\\10.10.10.1\BasketsIn\) with user name in the file name like (F0#CGDBANG000947532#logesh) at the end F0#CGDBANG000947532# copy to F0#CGDBANG000947532#username thanks – Logesh May 24 '14 at 17:21

2 Answers2

1

Easy:

copy "c:\A" "d:\%username%_A"

EDIT finally, after some of your comments here and in your other question, I understood your request (I think).

@echo off
for %%i in (%*) do if /i "%%~xi"==".eps" copy "%%i" "\\10.10.14.13\adman\in\displ\%%~ni%username%.%%~xi"
pause
Stephan
  • 53,940
  • 10
  • 58
  • 91
  • I want to copy the files in current folder to another location like (CURRENT FOLDER) file name like this (F0#CGDBANG000947532#) to another location like (\\10.10.10.1\BasketsIn) with user name in the file name like (F0#CGDBANG000947532#logesh) at the end F0#CGDBANG000947532# copy to F0#CGDBANG000947532#username thanks @Stephan – Logesh May 25 '14 at 09:15
  • @Logesh: In your question, you are saying, *‘I want to change the **selected file name**…’* – and now it turns out you wanted to rename *multiple files*. Please edit your question to make your specific problem clear. – Andriy M May 26 '14 at 12:00
  • Just noticed your update. Could you explaing please why are you using `%*`? I mean, it's not as if the OP is specifying file names in the command line. Or am I missing something? – Andriy M May 27 '14 at 17:44
  • @AndriyM: from his comments to his other (very similar) question (http://stackoverflow.com/questions/23847967/batch-script-file-name) I guessed, he wants to select a file in windows explorer and process it with "Send To". So `%1` would be the consequence. `%*` will make it possible to select several files and process them each. I think, that's what he want to do. Of course this is only a guess, because both of his questions are very unclear. So are his comments. – Stephan May 28 '14 at 06:20
0

If your file names do not have an extension or if you want the user name to be appended after the very end of the name (i.e. even after the extension), you could just use the following simple command:

COPY * \10.10.10.1\BasketsIn\*%USERNAME%

where USERNAME is a system environment variable that resolves to the user name of the current user.

If, however, you have names with extensions and you want the user name to be appended after the file name but before the file extension, you could use the ? mask character like this:

COPY * \10.10.10.1\BasketsIn\???????????????????????????????%USERNAME%.*

Just make sure you have provided enough ?s to cover the longest possible name in your case. If you are interested, you can learn more about this method in this excellent, in-depth Super User answer by dbenham:

One more note: this method may not work as expected with file names that have "multiple" extensions, i.e. like some.txt.doc.

Community
  • 1
  • 1
Andriy M
  • 76,112
  • 17
  • 94
  • 154
  • As you mentioned I have file names with extensions and I want the user name to be appended after the file name but before the file extension. But even when I add enough ??, it didn't take the full name. When I did it for (F0#CGDBANG000947532#.eps) I recd like (0#CGDBANG000947532#logesh.eps) without the First letter (F). Pls let me know where I go wrong..? – Logesh May 27 '14 at 07:07
  • That's strange. The exact command as the one in my post (except the target path) worked perfectly well for me, and I tried it with file names like yours – no lost characters, the new names were same with the user name added. I tried changing the first mask, `*`, to `F*` – thought something weird could be happening if the first letter was specified explicitly, but no, there was nothing wrong again. I'm puzzled, but I do have suspicion that something might be going on after the copying or perhaps you mistakenly copied files that did not have the first F in their names? – Andriy M May 27 '14 at 08:50
  • Thanks a lot and it works fine. I need little more help in the same situation, like Black&white files should go to B/W folder and Colour files should copy to Colour Folder. From the file name we can distinguish B/W & Colour, as the 4th character of file name will C or B as per the file. Like (F0#CG or F0#BG)_ F0#CGDBANG000947532# & F0#BGDBANG000947532#... thanks a lot in advance – Logesh May 27 '14 at 12:45
  • Ah, but that is a different problem now. It will be better if you create a new question for it. That'll increase your chances of getting a good suggestion. I'll be happy to take a look at it when I have time. – Andriy M May 27 '14 at 14:56
  • Sure I will post it... and thanks a lot for your help.. I want to learn batch script from start, where can I learn can u sugggest any..? – Logesh May 27 '14 at 16:31
  • I haven't used any specific online resources dedicated to batch scripts, nor have I read any written books about them, so probably no, I can't, sorry. I had already had some experience in batch scripting before I joined Stack Overflow, which I got by reading built-in help and experimenting. This site does help me to extend my knowledge some more, but that's about it. From the top of my head, there's [this forum](http://ss64.org/viewforum.php?id=2) that some SO users seem to be registered at. Not me, though, I only know about it because I've seen links to it in those users' answers or comments. – Andriy M May 27 '14 at 17:08
  • thanks anyhow you helped me a lot:) And one more, how can I execute the script for one particular file which I am selecting, when I have list of files in the same folder (though without changing the script for each) Like, 1.AA.eps, 2.BB.eps, 3.CC.eps and I wantto execute it only for 2nd BB.eps file in the same folder... – Logesh May 27 '14 at 17:19
  • You are probably asking about batch file parameters. Not sure but perhaps this question could be a good introduction: http://stackoverflow.com/questions/14286457/using-parameters-in-batch-files-at-dos-command-line – Andriy M May 27 '14 at 17:25