Echoing paths to log file shows \\ in path names instead of \

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
certx1164
Posts: 3
Joined: 25 Jan 2016 11:25

Echoing paths to log file shows \\ in path names instead of \

#1 Post by certx1164 » 25 Jan 2016 11:39

I have a batch file that moves a downloaded file after a download in Axway Secure Client. My batch file moves the file from the download destination folder to a "hot folder" (monitored by other application) where it is immediately processed. The batch file also echo's various output into a log file depending on successful or failed move. The move works fine, but the echoed text inserts an addition \ for every path delimiter, so that the destination in the log file is:

d:\\foldername\\foldername rather than d:\foldername\foldername

This folder name is obtained from the same %variable as the destination in the move operation, which works, so I'm not sure why it shows double \ in the log. Here is an example of the log entry, and below that, the actual batch file:

Log entry:
2016/01/25, 10:12:14.69, Moving XXXXXXXXXXXXXXXXXXXXXXXXXXXX.dat to D:\\ftpdata\\ENTKMONITOR, successful
(Name removed because this is confidential banking data)

Batch file:
set Year=%date:~10,4%
set Month=%date:~4,2%
set Day=%date:~7,2%

set Today=%Year%/%Month%/%Day%

move %1 %2 && (echo %Today%, %time%, Moving %1 to %2, successful >> \\fnb.cfbi.local\data\Apps\FTP\ftpdl\FTPAXWAYMOVE\movefile.bat.log) || (echo %Today%, %time%, Moving %1 to %2, failed >> \\fnb.cfbi.local\data\Apps\FTP\ftpdl\FTPAXWAYMOVE\movefile.bat.log)


Any help would be GREATLY appreciated!

TIA
CR

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Echoing paths to log file shows \\ in path names instead of \

#2 Post by Squashman » 25 Jan 2016 13:07

What program is executing your batch file? The only way the slashes would be getting doubled is if they were passed to the batch file that way.

certx1164
Posts: 3
Joined: 25 Jan 2016 11:25

Re: Echoing paths to log file shows \\ in path names instead of \

#3 Post by certx1164 » 25 Jan 2016 14:27

Squashman wrote:What program is executing your batch file? The only way the slashes would be getting doubled is if they were passed to the batch file that way.



It's being launched by the Axway Secure Client software. The command to do so is:

x:\BatchFiles\movefile.bat %f d:\ftpdata\entkmonitor

Where %f is the current filename, and d:\ftpdata\entkmonitor is the destination.

They are received by the batch file as %1 and %2. When moving the files, in the batch file, as you can see, it's simply

move %1 %2

Here's %2 obviously only has single \'s because the moves are successful. If %2 contained \\ between foldernames, it would fail. I'm using the same thing (%2) in echoing to the log file.

As far as functionality of the batch file, I'm not concerned, as it's working correctly in the move. It's really just bugging the hell out of me in the log file.

Thanks.

certx1164
Posts: 3
Joined: 25 Jan 2016 11:25

Re: Echoing paths to log file shows \\ in path names instead of \

#4 Post by certx1164 » 25 Jan 2016 14:45

Squashman wrote:What program is executing your batch file? The only way the slashes would be getting doubled is if they were passed to the batch file that way.


Maybe disregard my previous reply. I just did a few tests...using \, \\, \\\, and /\, as folder delimiters... seems those all work just fine with a windows/dos "move" *sigh*

kwsiebert
Posts: 43
Joined: 20 Jan 2016 15:46

Re: Echoing paths to log file shows \\ in path names instead of \

#5 Post by kwsiebert » 25 Jan 2016 16:40

As mentioned above, it's definitely coming from the initial command line that the batch is launched from. Most, if not all, file operations don't care if you have extra slashes in the path, which is why the move works. If the extra slashes in the log cause you a problem, you can try expanding the offending %2s to %~f2. I tested it briefly and it seems to reduce any number of slashes down to one, but I would personally leave things as they are.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Echoing paths to log file shows \\ in path names instead of \

#6 Post by Squashman » 25 Jan 2016 18:45

All you have to do is echo %1 and %2 at the top of the batch file which will prove that your thrid party program is causing the extra slashes.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Echoing paths to log file shows \\ in path names instead of \

#7 Post by foxidrive » 26 Jan 2016 09:10

Squashman wrote:All you have to do is echo %1 and %2 at the top of the batch file which will prove that your third party program is causing the extra slashes.


+1

Post Reply