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
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
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:
How does the Windows RENAME command interpret wildcards?
One more note: this method may not work as expected with file names that have "multiple" extensions, i.e. like some.txt.doc.
Related
I am creating a batch file that will install files into a certain location on a computer. this could be used for various things such as game mods, folder backups, etc. If i am trying to have the user type in the path they want the file to be sent to. How would I do that? I would like to have that path pasted into a .txt file, that way i can access it later in the program. I have tried the ">" and it works on putting the path into the file. How do I extract that information. "Direct Question" How can I take user input, and use it to paste files somewhere else in the computer using the user's path that was specified.
How many questions do you want for your money?
To input a string:
set /p "installdir=Install in which directory? "
At any point thereafter, you can use %installdir% to access the directoryname input.
If you need to save the directoryname in a file, then use
>"c:\wherever\you\want\filename.txt" echo %directoryname%
and to read it,
for /f "usebackqdelims=" %%a IN ("c:\wherever\you\want\filename.txt") do set "dirread=%%a"
or
set /p "dirread="<"c:\wherever\you\want\filename.txt"
and "pasting" or probably copying,
copy /b "x:\directory from\filename.whatever" "%dirread%\"
to copy the file "filename.whatever" from directory "x:\directory from\" to directory in the environment variable dirread as read by one of the previous two methods or substitute directoryname for dirread to use the directory name originally entered.
I have code that looks like this
%original%-added.txt
So if the original filename is
blue.txt
My code modifies that blue.txt file and the new file is then named
blue.txt-added.txt
How can I remove that first ".txt" so that I only get
blue-added.txt
Most likely a simple REN command is all you need. I'm assuming you always want to preserve the original file extension.
ren "%original%" "?????????????????????-added.*"
Just make sure there are at least as many ? as there are characters in the original name up until the .
Here are some results you can expect
original new
-------- ------------
blue.txt blue-added.txt
part1.part2.txt part1-added.part2.txt
You could use wildcards in your source file mask. The following would append "-added" to the base name of all .txt files:
ren *.txt ?????????????????????-added.*
See How does the Windows RENAME command interpret wildcards? if you want to understand why this works.
Try like this :
%original:~0,-4%-added.txt
I am trying to create a batch file (filehandling.bat)
I have a file in C:\Users\username\Downloads called "hita_2013_11_05_19_11_38.csv" where the date/time changes according to the date/time it is created
I need to rename this file to "hita.csv"
The problem comes because their will always be an existing "hita.csv" file in the directory that needs to remain there unless overwritten with the above file so the REN function isn't working because it is not overwriting the file
I also need it to make no changes(do nothing) to the existing "hita.csv" file if the "hita_2013_11_05_19_11_38.csv" file doesn't exist.
I've tried the following commands and can't get any to work: REN, MOV, ROBOCOPY /MOV
I've also tried:
IF EXIST "C:\Users\username\Downloads\Hita*.csv" (
DEL C:\Users\username\Downloads\Hita.csv
REN "C:\Users\username\DownloadsHita*.csv" Hita.csv
) ELSE (
Echo The file was not found.
)
but this command still deletes the "hita.csv" file for some reason
Change your test to IF EXIST "C:\Users\username\Downloads\Hita_*.csv" (note the underscore before the '*'). The * wildcard matches 0 or more characters, so it will match Hita.csv, Hita_01.csv, or HitaXYZ.csv.
Adding the underscore makes it only match files starting with Hita_ instead.
Your hita.csv matches the wildcard search of Hita*.csv, so it will delete it.
I believe you want your wildcard search to be Hita?*.csv. The question mark should act as an "exactly one", while the asterisk is "zero or more" characters, which means Hita.csv will not match that criteria.
I felt it was better to ask this separately rather than expect an answer from my comment on my previous post.
I already have variables set for the directory number %jobn% which is unique is there a way I can search for the unknown element to add to another variable, I know via the command line I can run Dir D09854* and I will get a single report with the full name, can this be collected somehow and add to a named variable?
S:\SWDA\HBOS>dir d09854*
Volume in drive S is Images
Volume Serial Number is FE8F-38FE
Directory of S:\SWDA\HBOS
18/02/2013 10:29 <DIR> D09854_Parent Test
I want to add the elements after "_" to a variable %DirDesc% so I can create the full path by combining %jobn%%DirDesc% to get "D09854_Parent Test"
dir d09854* /b will recover the full folder name in one line, without the extra cruft, if that's any use? What are you writing this widget in?
Does it have to be Good Old Fashioned DOS, or can the newer Command extensions be used?
With limited old DOS, I can't think of a way to get that into a SET Variable without piping it to a temporary batch file, having first ECHO'd a set variable= into it, and using >> in the pipe to append to it... and then CALL the temporary batch file to execute the command!
I am completely new to this, but I am trying to create a .bat file that will allow me to rename a pair of files within a designated folder and move them into a subfolder. The part I am having trouble with is that I am wanting a prompt to come up to identify/select the files to be renamed and moved.
Example file names are:
A1234, A1235, A1236, B1234, B1235, B1236, etc.
Is there a way to bring up a prompt that allows the user to type the shared name (ex 1234)of the files and rename and move both files to the designated subfolder?
Any and all help would be appreciated!
Suggested approach
for part of problem
part I am having trouble with is that I am wanting a prompt to come
up to identify/select the files to be renamed and moved. Is there a
way to bring up a prompt that allows the user to type the shared name
(ex 1234)of the files and rename and move both files to the designated
subfolder?
Do a search operation using wildcard, like "?1234" for the case highlighted above ( should be made generalized for all acceptable and expected patterns "*1234*" is the generic most )
Now do a RENAME inside a For loop on the results obtained by search.
As you suggest you are a newbie with Batch, following tutorials will help you build your file. Look for elements like Variables, For Loop
Batch Tutorial
Here you go
#echo off
set /p file=Please type shared name:
for %%a in (C:\Folder\?%file%.*) do (
move "%%a" subdir
ren "subdir\%%a" newname.*
)