Wildcards and the MOVE command in a batch file - Wildcard not recognised as such - batch-file

I have a batch file with the following line in it:
move d:\cdr\C0*.%yyyy%-%mm%-%dd%*.csv d:\CDRArchive\%yyyy%%mm%\
where the variables yyyy mm and dd are for their resective parts of a given date. When I run this, the batch file parses the variables out correctly, but I doesn't recognise the wildcard character *, so I get the following line:
> move d:\cdr\archive\C0*.2013-09-08*.csv d:\CDRArchive\201309\
A duplicate file name exists, or the file
cannot be found.
Any help is much appreciated.

It works fine, once the target folder is created. Note that the error message you supplied shows that the filespec is wrong or the folder is wrong. The error message you get when they are right is shown below. (tested in Windows 8)
d:\>move d:\cdr\C0*.2000-10-01*.csv d:\CDRArchive\200010\
Cannot move multiple files to a single file.
d:\>md d:\CDRArchive\200010\
d:\>move d:\cdr\C0*.2000-10-01*.csv d:\CDRArchive\200010\
d:\cdr\C0abc.2000-10-01.aaa.csv
d:\cdr\C0abc.2000-10-01.bbb.csv
d:\cdr\C0abc.2000-10-01.ccc.csv
3 file(s) moved.

Related

How to make sure date/time syntax is correct in batch script

I have a line in a batch file that renames a file with a date and time appended to it.
rename "C:\Program Files (x86)\File Directory\sub directory\logs\Backups\Client.txt" Client%date:~7,2%%date:~4,2%%date:~10,4%%time:~0,2%%time:~3,2%%time:~6,2%.txt
This works fine, except if the first time parameter (%time:~0,2%) is a single digit. It will error with an incorrect syntax command. I understand why it occurs (there's a similar post here) but can't seem to get the correct syntax to make the command run successfully when the hour parameter is a single digit (between 01-09).
What command syntax do I need to add to make sure the command works with single digits for the hour ?
set hour=%time: =0%
rename "C:\Program Files (x86)\File Directory\sub directory\logs\Backups\Client.txt" Client%date:~7,2%%date:~4,2%%date:~10,4%%hour:~0,2%%time:~3,2%%time:~6,2%.txt

batch file to automate tree command > pdf file

I am new to batch files but was looking to create one that would use the tree command to write a .txt file of the directory in which the batch file is located and then convert that .txt file to a Word file or PDF that the every day user could view.
This was my attempt at the first part of the process;
tree %~dp0 > %~dp0/"Folder Contents.txt" /A /F
but this gave me an "Invalid Path" message in the .txt file
If anyone could point me in the right direction it would be greatly appreciated.
Thanks in advance for your help.
JosefZ has placed the correct command in the comments but I thought I would add a bit of an explanation here:
Think of how you path would look like with your command. It would be like C:\PathTo\Batch\/"FolderContent.txt" which actually is not a valid path.
%~dp0 will end with a \ so the / in the command from the question is syntactically incorrect.
Further the double quotes should be placed around the total path as JosefZ did in his comment. If you do not do that the path will contain these quotes and will be invalid.
JosefZ further added double quotes and a single . around and at the end of %~dp0 after your tree command. The quotes are there to include possible whitespaces into your folder-path and the . to include folders with subfolders as well. You will get an error message if you do not.
Last thing is that he placed the output file at the beginning of the command and got rid of spaces. You can basically place your output file anywhere however. Although you should notice that you should not contain spaces between > and your output-file-path.

output batch file log to seperate directory

I have a batch file which currently output a log file by calling its extension
(sqlplus #Down.sql "test" "testl") > "%~dpn0.log"
which outputs the log file to the same location of the batch folder.
e.g. C:\Folder1\run.bat
of course, the log file would be run.log
I would like to output the log file to a log folder.
similar to C:\Folder1\log\run.log.
Anyhelp is appreciated in pointing out hwo to do it in my source code. Thanks
...> "c:\folder1\log\%~n0.log"
should suffice. The trick is the %0 means the name of the batch, and this can be mofified by ~letters which may be used in any combination.
The letters that are significant are listed conveniently in the for documentation, accessible from
for /?
executed from the prompt.

Select multiple files with the same extension in .bat file

i found a script that converts a certain subtitle form , but to make it work i need to rename the subtitle file to "test.srt", then after coonverting , i rename it back to its original name , and its really annoying to keep repeating the process and to name each subtitle file on its own , i want the script to convert all the files in that folder that ends up with ".srt", not only to "test.srt" file
the bat file is like this :
"perl ps3_friendly_arabic_subs_converter.pl test.srt"
it uses the perl script to convert the file named "test.srt" , i tried to make it convert all the files that ends up with ".srt" , and i edited it this way
"perl ps3_friendly_arabic_subs_converter.pl *.srt"
and yeah it didn't work , so please anyone knows how ? thanks in adnvance
for %a in (*.srt) do perl ps3_friendly_arabic_subs_converter.pl "%a"
For each .srt file (in current folder), execute the indicated script passing the file as argument.
To execute it from a batch file, it is necessary to escape the percent signs, replacing each % with %%

copy command in DOS is not recognizing when filename has '='

I wrote batch script to copy a file and write a log.
However copy is not working when the file name is like this:
8001#121122213500#1002#00#M=MRN100#C=Test_Large_File2.wav
On further checking I found this is because of the = in the filename.
I also tested individually. When I use copy *.wav d:\wav file is getting copied, but when I use
copy 8001#121122213500#1002#00#M=MRN100#C=Test_Large_File2.wav d:\wav
I get an message that the file is not found.
Can any one help me in resolving this. I also tried searching old posts here but couldn't find any.
Thanks
You need to quote the filename
copy "8001#121122213500#1002#00#M=MRN100#C=Test_Large_File2.wav" d:\wav

Resources