I am using Connect:Direct process to run a DOS command to get the list of files available for collection.
If the files are available in the collection folder then the file details gets redirected to the output file (dirfile.lst). Then Connect:Direct will do a collection for those files and then delete dirfile.lst.
If there are no files in the collection folder it is expected that the dirfile.lst will be empty. And Connect:Direct will collect no files and delete dirfile.lst.
The command which I am using is
(dir "G:\Outbound\EDI\USCOLL_FTP\*" /a-d/oN ) > "F:\Sterling\Connect Direct v4.6.00\Server\program\2172047.dirfile.lst"
The problem which I am facing is when the file filter is . or *.* and if there are no files in the folder then the command throws a response "File Not Found". Connect:Direct process fails when it gets any response from the command. Interestingly I only face this issue is the file filter is . or * for any other file filter I am not getting this "File Not Found" response even though there are no files in the folder.
If I use 2> Null to fix the issue it won't display any other exceptions, hence I don't prefer to use this?
Is there a way I can get rid of File not Found message which I get when I use * and . file filters?
Any help or suggestions will be much appreciated.
It's not pretty, but this should do the trick:
>NUL 2>NUL DIR "G:\Outbound\EDI\USCOLL_FTP\*" /a-d/oN && (DIR "G:\Outbound\EDI\USCOLL_FTP\*" /a-d/oN > "F:\Sterling\Connect Direct v4.6.00\Server\program\2172047.dirfile.lst") || ECHO. > "F:\Sterling\Connect Direct v4.6.00\Server\program\2172047.dirfile.lst"
I know you didn't want to use 2>Nul but it's the best I could get. Hopefully someone will provide a better answer.
Related
I'm having issues renaming the following file using a batch (.bat) file. I'm using Windows 7.
Here's my syntax:
SET MY_PATH=%~dp0
ren %MY_PATH%\MY_RECAP* DBS.txt
I'm attempting to rename a file that has a changing file name due to the current date being appended to the end of the MY_RECAP file name (such as MY_RECAP_MMDDYYYY). I'm using a wildcard to rename that file to DBS.txt
This still won't work. Any ideas?
There are quite many solutions to do this. The first and easier one is:
#ren "%~dp0MY_RECAP_*" "DBS.txt"
If you want to check a DBS.txt file already exists, use an if exist statement:
#if not exist "%~dp0DBS.txt" (#ren "%~dp0MY_RECAP_*" "DBS.txt")
An additional note: If in your batch file you have specified somewhere above #echo off or echo off, remove the # symbols from everywhere.
I have ZERO bat knowledge so thought I would ask here, if I may.
I have an image C:\Users\Dane\Pictures\Doom.jpg. I wish for this image to be copied and for it to be renamed to the exact name of 379 non-image type files which are in another folder which is G:\Doom. So I will have the same image 379 times but named to match the 379 files.
Would anyone be kind enough to write a bat file to do that? Thank you in advance.
This site is not a free code writing service; Rather give the subject an attempt and we will be happy to assist you. However, because I'm nice, I have a response for you.
This problem is pretty common and can be solved very easily using a FOR statement. In this example we will be searching a directory for every item stored inside. Each item will be added to the integer %%A. For more information do FOR /? inside a command window.
for %%a in ("Directory") DO (Action)
For copying files, we will use the copy command. Please keep note that we will be using parameter extensions to expand the %%A to have no extension using %%~na. More info here: Parameter Extensions
This script will copy & rename Doom.jpg to G:\Doom for each item in the directory.
Batch File:
for %%a in ("G:\Doom\*") do (copy "C:\Users\Dane\Pictures\Doom.jpg" "G:\Doom\%%~na.png")
Command Prompt:
for %a in ("G:\Doom\*") do (copy "C:\Users\Dane\Pictures\Doom.jpg" "G:\Doom\%~na.png")
ANSWER: I have found a way of doing it. Go into the directory and type del *.*. That works. Note: typing del C:\wamp64\www\MyTest does not work. Nor does del background.jpg,..
QUESTION:
During a test programming (NodeWebkit) I have created a file with a faulty file name. The file name I have created is:
background.jpg,..
Yes, that is a comma and two periods at the end.
I cannot seem to be able to delete this file now, even in File Explorer.
Please help, how can I delete this file?
EDIT:
When I use the command line I get the following:
C:\wamp64\www\MyTest>del background.jpg,..
Could Not Find C:\wamp64\www\MyTest\background.jpg
C:\wamp64\www\MyTest\*, Are you sure (Y/N)? y
When I type y and return it does nothing.
Also note: When I do dir in the command line it includes 10/10/2017 17:51 82,792 background.jpg,..
ANSWER: I have found a way of doing it. Go into the directory and type del .. That works. Note: typing del C:\wamp64\www\MyTest does not work. Nor does del background.jpg,..
I have read many posts covering copy and xcopy, but i am unable to get my command to work.
I aim is to create a batch file that will do the following;
Search a directory structure for a list of files 'names only' if found copy them to another directory. If not found create an error list.
The txt format of files I am looking for can be in any format however in testing i have a text file like this;
1603010853
1603020845
1603141400
1604061215
The files are .PDF or .TIF
The directory structure that I am searching is like this;
X:DEL>16>160314>1603141400.pdf
X:DEL>16>160301>1603010853.tif
I am struggling to get it to work as the list is not the full path.
for /f "tokens=*" %i in (File-list.txt) DO xcopy /S/E "c:Test\In%i" "c:out"
Thanks in advance
Fostersimported
Alrighty, if tool doesn't matter much, I'd suggest going with the PowerShell script attached to this SuperUser post. It seems to do everything you want (including logging errors). You'd need only copypasta that into a text file, name it accordingly, and go from there.
I have a simple xcopy script that I'm running from the command line that reads a CSV file of directories and file names. I've used a very similar script with no problems before. Here is the script:
Z:\HOME\>for /f "delims=, tokens=1,2,3,4" %i in (Z:\HOME\MissingImages.csv) do
echo f | xcopy "Y:\%j\%k\%l" "C:\Horizon\%j\%k\%l" >> Z:\HOME\MissingImagesLog.txt
However, it is not copying any of the files over
Here is an entry from the log file:
Does C:\Horizon\K\00\6bef500f.IMG specify a file name
or directory name on the target
(F = file, D = directory)? f
0 File(s) copied
It's finding the images because if I change the root directory to something else the script will just populate the log file with 0 File(s) copied for all entries, so the files are there and can be seen...
Also, the Z:\ drive is on a network and not local, but again I have used a very similar script across a network without problems (it just takes longer).
I've tried different options like /i, /s, etc. but I can't seem to get it to copy any files over.
xcopy will also report 0 File(s) copied if you use forward slashes "/" in paths instead of backslashes "\", though ONLY if you've enclosed the path in quotes.
This fails with "0 File(s) copied"
xcopy "pathname1/file" pathname2\file
This fails with "Invalid number of parameters"
xcopy pathname1/file pathname2\file
This works just fine
xcopy pathname1\file pathname2\file
It asks because it doesn't know whether you want to copy to directory (to be created) or you provide the full target pathname.
This will ask:
xcopy pathname1\file.from pathname2\file.to
However, adding slash will tell that you copy to directory:
xcopy pathname1\file.from pathname2\to\
But I haven't found the way to tell explicitly that I want to copy and rename file, except
echo Y | xcopy pathname1\file.from pathname2\file.to
I played a bit with your case (with for, do and xcopy) and found out that even if it asks Does SOMEFILE specify a file name or directory name on the target (F = file, D = directory)? it is provided with f from echo and it's copied successfully. Thus, it's not a problem with file/directory specifying, but with copying through network itself.
Well, that's annoying; I found the issue. It looks like when I generated my CSV file, it put a space at the end of each line, so xcopy was looking for files that had a space after the extension.
The thing that was throwing me off was that it was finding the files, but couldn't copy them, making me think it was a network or xcopy issue.
I just ran a sed script to remove the eol spaces and the xcopy script is now working as expected.