Javascript和额外的零。 [英] Javascript and extra zeros.

查看:76
本文介绍了Javascript和额外的零。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先请允许我说我绝不是一个熟练的程序员,所以我可能在我尝试编码我的

问题时犯了十几个错误。我会告诉你这个问题,以便你知道我想要做什么,我会给你我的代码,这样你就可以看到我的

clusterf * ck。


问题在于:


在工作中我有大约20位为我工作的摄影师。每个人都有一个

照片创意号码(我的是102,我的老板是101,我的助手'

是103等)当他们拍照时他们给给客人一张卡

然后当他们填满了他们的存储卡时,他们会回到办公室加上他们的b $ b $。$

图片被加载到自己的文件夹中。每个摄影师都有

5000个文件夹可供使用。他们拖了一张标有

" dscfxxxx.jpg"的图片。 (x = 0000,当每个活塞被取出时计数)

到最低的未填充文件夹(1020001,1020002等),然后将

放在服务器上的那些文件夹中。客人来到柜台并且

在屏幕上输入他们的号码,然后将输入的数字拉到

文件夹中的图像。


使用如此多的图像和文件夹会导致错误和

频繁的客人输入的数字与

的图片不符。这是因为摄影师不小心把它放在了错误的文件夹中,或者发错了卡片。我无法处理

发错卡,因为错误发生但我知道它可以是

编程自动从媒体卡中取出图片,

创建一个文件夹,然后将图片传输到该文件夹​​。


我的解决方案和我的问题:


我写了一个javascript非常难看 -


< script language =" javascript">


/ * alows user输入起始文件夹和拍摄的照片数量和

然后将它们变成数字* /


folder = window.prompt(''起始文件夹'',''默认' ');

picnumber = window.prompt(''拍照?'',''默认'');

f2 = parseFloat(文件夹);

p2 = parseFloat(picnumber);

/ *将拍摄的照片数量添加到起始文件夹编号中

确保存在适当数量的文件夹并且告诉用户

起始文件夹和结束文件夹是* /


varAdd = f2 + p2-1;

varImg = 0000 + p2;

document.write( ''起始文件夹'',f2,''< br>'');

document.write(" Ending folder should be + varAdd +"< br>< br>");


/ *用于使系统达到文件传输标准的命令* /

document.write(" cd ..< br>")

document.write(" cd documents and settings\christopher

neu\desktop< br>")

document.write(" mkdir transfer< br>")

document.write(" cd transfer< br> ;")


/ *将文件从smartmedia复制到传输文件夹* /


document.write(''copy d:\ dcim \100_fuji \ * .jpg< br>'')


/ *通过传输

文件夹计算并写入适当数量的文件夹" MKDIR"命令正确传输文件* /


for(count = f2; count< = varAdd; count ++)

document.write(" mkdir" + count +"< br>");


/ *将图片移动到适当的文件夹中* /


for(count = p2 ; count< = varImg; count ++)

document.write(" move dscf" + count +" .jpg< br>")


< / script>


- 这个脚本成功地允许摄影师输入他们开始的

文件夹编号以及他们拍摄的照片数量

创建适当数量的文件夹,以便每张图片都有自己的

文件夹。然后,我试图让脚本创建正确的

命令,将每张照片移动到其等效文件夹。 dscf0001.jpg到

最低可用文件夹dscf0002.jpg到下一个最低等等。


这是这一步的问题:


我试图通过

计算出适当数量的图像,从0000开始计算并添加拍摄的照片数量和

然后将其与屏幕上的文本dscf相结合。和.jpg所以它b / b
读取dscf0001.jpg但是它不断丢掉额外的零并且给我

我dscf1.jpg


一旦完成运行,摄影师将复制命令文本

并将其粘贴到dos命令行,它会将每张图片移动到

它正确的文件夹中消除了一个主要的错误区域

有我们花了一个销售基调,因为人们都喜欢,好吧,这不是很好。不要担心找到它。


我也有在更改

目录命令中显示斜杠的问题。他们刚被淘汰,我不知道如何让他们出现。


如果有人可以帮助我,我们将不胜感激!


PS对不起,这是解决问题,而不是直截了当的说明

但是我坚信这个问题的背景故事带来了一个更快捷的解决方案。

First off let me say that I am by no means a skilled programmer so i
probably have made a dozen mistakes in my attempt at coding my
problem. I will tell you the problem so that you have an idea of what
i am trying to do and I will give you my code so you can see my
clusterf*ck.

Here is the problem:

At work I have about 20 photographers who work for me. Each one has a
photo idea number (mine is 102 and my bosses is 101 and my assistant''s
is 103 etc.) When they take a picture they give a card to the guest
and then when they have filled up thier memory cards they return to
the office to load thier pictures.

The pictures get loaded into thier own folders. Each photographer has
5000 folders to work from. they drag one picture labeled
"dscfxxxx.jpg" (x = 0000 which counts up as each pisture is taken)
into the lowest unfilled folder (1020001, 1020002, etc.) and then puts
those folders on the server. the guest comes to the counter and
enters thier number on the screen and the image within the folder of
the number entered is then pulled up.

Working with so many images and folders leads to mistakes and
frequently guests enter numbers that do not match up to the picture of
them. This is because the photographer accidentally put it in the
wrong folder or handed out the wrong card. I can not deal with
handing out the wrong card as mistakes happen but i know it can be
programmed to automattically take the pictures from the media card,
create a folder and then transfer the picture to that folder.

My solution and my problem:

I have written a javascript that is very ugly--

<script language="javascript">

/*alows user to input starting folder and amount of photos taken and
then makes them into numbers*/

folder = window.prompt(''starting folder'',''default'');
picnumber = window.prompt(''pictures taken?'',''default'');
f2 = parseFloat(folder);
p2 = parseFloat(picnumber);
/*adds the amount of photos taken to the starting folder number to
ensure proper amount of folders are present and tells user what the
starting folder and end folders are*/

varAdd = f2+p2-1;
varImg = 0000+p2;
document.write(''Starting folder is '',f2,''<br>'');
document.write("Ending folder should be " + varAdd + "<br><br>");

/*Commands used to bring system to standard for file transfer*/

document.write("cd..<br>")
document.write("cd documents and settings\christopher
neu\desktop<br>")
document.write("mkdir transfer<br>")
document.write("cd transfer<br>")

/*copies files from smartmedia to transfer folder*/

document.write(''copy d:\dcim\100_fuji\*.jpg<br>'')

/*calculates and writes proper amount of folders in the transfer
folder via the "mkdir" command to properly transfer files*/

for (count=f2;count<=varAdd;count++)
document.write("mkdir " + count +"<br>");

/*moves pictures into proper folders*/

for (count=p2;count<=varImg;count++)
document.write("move dscf" + count +".jpg <br>")

</script>

--this script successfully allows the photographer to input what
folder number they started on and how many photos they took then
creates the proper amount of folders so each pictures has its own
folder. I then am trying to have the script create the proper
commands to move each photo to its equivalent folder. dscf0001.jpg to
the lowest available folder dscf0002.jpg to the next lowest etc.

here is the problem with that step:

I am trying to have it sequence out the proper number of images by
counting starting with 0000 and adding the number of photos taken and
then combining it onscreen with the text "dscf" and ".jpg" so that it
reads "dscf0001.jpg" but it keeps dropping the extra zeros and gives
me "dscf1.jpg"

Once it is done running the photographer will copy the command text
and paste it to the dos command line and it will move every picture to
its correct folder for them eliminating a major area of mistake that
has cost us a tone of sales because people are like,"well it is no
biggie. Don''t worry about finding it."

I am also having the problem of displaying the slashes in the change
directory commands. they are just eliminated and i am not sure how to
make them appear.

If someone can help me with this it will be greatly appreciated!

P.S. sorry this is sol drawn out and not really straight to the point
but i am a firm believer that backstory of the problem brings about a
much swifter solution.

推荐答案

坦克写道:
首先让我说我不是一个熟练的程序员所以我可能我试图编码我的问题时犯了十几个错误。我会告诉你这个问题,以便你知道我想要做什么,我会给你我的代码,这样你就可以看到我的
clusterf * ck。
问题在于:

在工作中,我有大约20名为我工作的摄影师。每个人都有一个
照片创意号码(我的是102,我的老板是101,我的助手是103等)。当他们拍照时,他们会给客人一张卡片。 >然后当他们填满了他们的存储卡时,他们会回到办公室去加载他们的照片。

图片被加载到他们自己的文件夹中。每位摄影师都有5000个文件夹可供使用。他们拖了一张标有
dscfxxxx.jpg的照片。 (x = 0000,当每个活塞被取出时计数)进入最低的未填充文件夹(1020001,1020002等),然后将这些文件夹放在服务器上。客人来到柜台,然后在屏幕上输入他们的号码,然后将所输入号码的文件夹中的图像拉出来。

使用这么多的图像和文件夹导致错误和
经常客人输入与他们的图片不符的数字。这是因为摄影师不小心把它放在错误的文件夹里或者发错了卡片。由于错误发生我无法处理发错卡但是我知道它可以被编程为自动从媒体卡中取出图片,
创建一个文件夹,然后传输图片到那个文件夹。

我的解决方案和我的问题:

我写了一个非常难看的javascript -

< script language = javascript>

/ * alows用户输入起始文件夹和拍摄的照片数量然后将它们分成数字* /

folder = window .prompt(''起始文件夹'',''默认'');
picnumber = window.prompt(''拍摄的照片?'',''默认'');
f2 = parseFloat(文件夹);
p2 = parseFloat(picnumber);

/ *将拍摄的照片数量添加到起始文件夹编号中以确保存在适当数量的文件夹并告诉用户什么
起始文件夹和结束文件夹是* /

varAdd = f2 + p2-1;
varImg = 0000 + p2;
document.write(''Starting folder is'',f2,''< br>'');
document.write(" Ending folder should be + varAdd +"< br>< br>");

/ *用于使系统达到文件传输标准的命令* /

document.write (cd ..< br>)
document.write(" cd documents and settings\christopher
neu\desktop< br>")
文件。 write(" mkdir transfer< br>")
document.write(" cd transfer< br>")
/ *将文件从smartmedia复制到传输文件夹* /

document.write(''copy d:\dcim \100_fuji \ * .jpg< br>'')

/ *计算并写入适当数量的文件夹在转移
文件夹中通过mkdir命令正确传输文件* /

for(count = f2; count< = varAdd; count ++)
document.write(" mkdir" + count +"< br> ");

/ *将图片移动到适当的文件夹中* /

for(count = p2; count< = varImg; count ++)
document.write( " move dscf" + count +" .jpg< br>")

< / script>

- 此脚本成功让摄影师输入什么
他们开始的文件夹编号和他们拍摄了多少张照片
创建了适当数量的文件夹,因此每张图片都有自己的
文件夹。然后我尝试让脚本创建正确的
命令,将每张照片移动到其等效文件夹。 dscf0001.jpg到最低可用文件夹dscf0002.jpg到下一个最低等等。

这是步骤的问题:

我想要有它通过从0000开始计数并添加拍摄的照片数量然后将其与屏幕上的文本dscf组合来排序正确数量的图像。和.jpg所以它读取dscf0001.jpg但它不断删掉额外的零并给出了dscf1.jpg

一旦完成运行,摄影师将复制命令文本
并将其粘贴到dos命令行,它会将每张图片移动到它正确的文件夹中,消除了一个主要的错误区域,因为人们喜欢这样做,因为人们很喜欢,好吧不是
biggie。不要担心找到它。

我也有在更改
目录命令中显示斜杠的问题。它们刚被淘汰,我不知道如何让它们出现。

如果有人可以帮助我,我们将不胜感激!

P.S。对不起,这是解决问题,而不是直截了当的
但我坚信,问题的背景故事会带来更快捷的解决方案。
First off let me say that I am by no means a skilled programmer so i
probably have made a dozen mistakes in my attempt at coding my
problem. I will tell you the problem so that you have an idea of what
i am trying to do and I will give you my code so you can see my
clusterf*ck.

Here is the problem:

At work I have about 20 photographers who work for me. Each one has a
photo idea number (mine is 102 and my bosses is 101 and my assistant''s
is 103 etc.) When they take a picture they give a card to the guest
and then when they have filled up thier memory cards they return to
the office to load thier pictures.

The pictures get loaded into thier own folders. Each photographer has
5000 folders to work from. they drag one picture labeled
"dscfxxxx.jpg" (x = 0000 which counts up as each pisture is taken)
into the lowest unfilled folder (1020001, 1020002, etc.) and then puts
those folders on the server. the guest comes to the counter and
enters thier number on the screen and the image within the folder of
the number entered is then pulled up.

Working with so many images and folders leads to mistakes and
frequently guests enter numbers that do not match up to the picture of
them. This is because the photographer accidentally put it in the
wrong folder or handed out the wrong card. I can not deal with
handing out the wrong card as mistakes happen but i know it can be
programmed to automattically take the pictures from the media card,
create a folder and then transfer the picture to that folder.

My solution and my problem:

I have written a javascript that is very ugly--

<script language="javascript">

/*alows user to input starting folder and amount of photos taken and
then makes them into numbers*/

folder = window.prompt(''starting folder'',''default'');
picnumber = window.prompt(''pictures taken?'',''default'');
f2 = parseFloat(folder);
p2 = parseFloat(picnumber);
/*adds the amount of photos taken to the starting folder number to
ensure proper amount of folders are present and tells user what the
starting folder and end folders are*/

varAdd = f2+p2-1;
varImg = 0000+p2;
document.write(''Starting folder is '',f2,''<br>'');
document.write("Ending folder should be " + varAdd + "<br><br>");

/*Commands used to bring system to standard for file transfer*/

document.write("cd..<br>")
document.write("cd documents and settings\christopher
neu\desktop<br>")
document.write("mkdir transfer<br>")
document.write("cd transfer<br>")

/*copies files from smartmedia to transfer folder*/

document.write(''copy d:\dcim\100_fuji\*.jpg<br>'')

/*calculates and writes proper amount of folders in the transfer
folder via the "mkdir" command to properly transfer files*/

for (count=f2;count<=varAdd;count++)
document.write("mkdir " + count +"<br>");

/*moves pictures into proper folders*/

for (count=p2;count<=varImg;count++)
document.write("move dscf" + count +".jpg <br>")

</script>

--this script successfully allows the photographer to input what
folder number they started on and how many photos they took then
creates the proper amount of folders so each pictures has its own
folder. I then am trying to have the script create the proper
commands to move each photo to its equivalent folder. dscf0001.jpg to
the lowest available folder dscf0002.jpg to the next lowest etc.

here is the problem with that step:

I am trying to have it sequence out the proper number of images by
counting starting with 0000 and adding the number of photos taken and
then combining it onscreen with the text "dscf" and ".jpg" so that it
reads "dscf0001.jpg" but it keeps dropping the extra zeros and gives
me "dscf1.jpg"

Once it is done running the photographer will copy the command text
and paste it to the dos command line and it will move every picture to
its correct folder for them eliminating a major area of mistake that
has cost us a tone of sales because people are like,"well it is no
biggie. Don''t worry about finding it."

I am also having the problem of displaying the slashes in the change
directory commands. they are just eliminated and i am not sure how to
make them appear.

If someone can help me with this it will be greatly appreciated!

P.S. sorry this is sol drawn out and not really straight to the point
but i am a firm believer that backstory of the problem brings about a
much swifter solution.



这是我为javascript编写的printf模拟器。它可以帮助你确定这样的事情。如果你不熟悉C,你可能会想要阅读关于printf()函数的手册(只有google)

http://www.vladdy.net/Demos/printf.html


-

Vladdy
http:// www。 klproductions.com



Here is a printf emulator I wrote for javascript. It should help you
with formating things like that. If you are unfamiliar with C, you may
want to read a manual on printf() function (just google one)

http://www.vladdy.net/Demos/printf.html

--
Vladdy
http://www.klproductions.com


2004年1月12日18:04:44 -0800,Tank< cn ** @ neuagency.com>写道:


< snipped description and code>
On 12 Jan 2004 18:04:44 -0800, Tank <cn**@neuagency.com> wrote:

<snipped description and code>
我试图通过
从0000开始计数并添加拍摄的照片数量,然后将其与屏幕上的文本dscf相结合。和.jpg所以它读取dscf0001.jpg但它不断删除额外的零并给出了dscf1.jpg。


要填充数字,您可以调用此函数:


//输入:数字 - 要填充的数字(整数)

// paddedLength -

//填充(整数)之后所需的数字长度

//输出:填充前导零的字符串

//相等于paddedLength参数

//注意:如果传递的数字长于

/ / paddedLength参数,数字将保持不变

//(即不会出现填充)

//

函数padZeros(number,paddedLength ){

返回''00000000''。substr(

0,

paddedLength - 字符串(数字).length)+字符串(数字) );

}


我也遇到了在更改
目录命令中显示斜杠的问题。它们刚被淘汰,我不知道如何让它们出现。


所以,要创建dscf0013.jpg,你可以写:


var photoNumber = 13;

var filename =''dscf''+ padZeros(photoNumber,4)+''.jpg'';


至于消失的反斜杠:这是因为一个反斜杠

(以字符串为单位)用于创建转义字符。例如,


alert(这是在第一行。\\ n这是在第二行。;


将显示一个包含两行文本的警告框。 ''\ n''在两个句子之间插入一个

的新行。要使用文字反斜杠,请将两个

放在一起:


alert(" C:\\ Windows \\Readme.txt") ;


那会显示,C:\ Windows \ Readme.txt


你的脚本还有其他几个问题(缺少类型检查,

SCRIPT标签中没有类型属性)但对我来说太晚了(时间紧迫)

现在对它们发表评论。其他人会接受他们,我很有信心。

P.S.对不起,这是解决问题,而不是直截了当的
但我坚信,问题的背景故事会带来更快捷的解决方案。
I am trying to have it sequence out the proper number of images by
counting starting with 0000 and adding the number of photos taken and
then combining it onscreen with the text "dscf" and ".jpg" so that it
reads "dscf0001.jpg" but it keeps dropping the extra zeros and gives
me "dscf1.jpg"
To pad a number, you can call this function:

// Input: number - The number (integer) to be padded
// paddedLength - The desired length of the number after
// padding (integer)
// Output: A string padded with leading zeros that is equal in
// length to the paddedLength argument
// Note: If a number is passed that is longer than the
// paddedLength argument, the number will be unchanged
// (i.e. no padding will occur)
//
function padZeros( number, paddedLength ) {
return ''00000000''.substr(
0,
paddedLength - String( number ).length ) + String( number );
}

I am also having the problem of displaying the slashes in the change
directory commands. they are just eliminated and i am not sure how to
make them appear.
So, to create dscf0013.jpg, you could write:

var photoNumber = 13;
var filename = ''dscf'' + padZeros( photoNumber, 4 ) + ''.jpg'';

As for the disappearing backslashes: this is because a single backslash
(in a string literal) is used to create escape characters. For example,

alert( "This is on the first line.\nThis is on the second line." );

would display an alert box that has two lines of text. The ''\n'' inserts a
new line between the two sentences. To use a literal backslash, place two
together:

alert( "C:\\Windows\\Readme.txt" );

That would display, C:\Windows\Readme.txt

There are several other problems with your script (lack of type checking,
no type attribute in the SCRIPT tag) but it''s too late (time-wise) for me
to comment on them now. Someone else will pick up on them, I''m sure.
P.S. sorry this is sol drawn out and not really straight to the point
but i am a firm believer that backstory of the problem brings about a
much swifter solution.



不要。它比以下更好,更优选:这不是
工作。为什么?"


希望有所帮助,

Mike


-

Michael Winter
M.******@blueyonder.co.inva 盖子(将.invalid替换为.uk以回复)



Don''t be. It''s far better, and much more preferable, than: "This doesn''t
work. Why?"

Hope that helps,
Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)


Michael Winter< M。****** @ blueyonder.co.invalid>在消息新闻中写道:< op ************** @ news-text.blueyonder.co.uk> ...
Michael Winter <M.******@blueyonder.co.invalid> wrote in message news:<op**************@news-text.blueyonder.co.uk>...
2004年1月12日18: 04:44 -0800,Tank< cn ** @ neuagency.com>写道:

<剪切描述和代码>
On 12 Jan 2004 18:04:44 -0800, Tank <cn**@neuagency.com> wrote:

<snipped description and code>
我试图让它通过计数开始计算出适当数量的图像0000并添加拍摄的照片数量,然后将其与屏幕上的文字dscf相结合。和.jpg所以它读取dscf0001.jpg但是它不断删除额外的零并给出了dscf1.jpg
I am trying to have it sequence out the proper number of images by
counting starting with 0000 and adding the number of photos taken and
then combining it onscreen with the text "dscf" and ".jpg" so that it
reads "dscf0001.jpg" but it keeps dropping the extra zeros and gives
me "dscf1.jpg"



要填充数字,你可以调用这个函数:
//输入:数字 - 要填充的数字(整数)
// paddedLength -
//填充后所需的数字长度(整数)
//输出:字符串用
//长度等于paddedLength参数的前导零填充
//注意:如果传递的数字长于
// paddedLength参数,则数字将为保持不变
//(即不会出现填充)
//
功能padZeros(number,paddedLength){
返回''00000000''。substr(
0 ,
paddedLength - 字符串(数字).length)+字符串(数字);
}



To pad a number, you can call this function:

// Input: number - The number (integer) to be padded
// paddedLength - The desired length of the number after
// padding (integer)
// Output: A string padded with leading zeros that is equal in
// length to the paddedLength argument
// Note: If a number is passed that is longer than the
// paddedLength argument, the number will be unchanged
// (i.e. no padding will occur)
//
function padZeros( number, paddedLength ) {
return ''00000000''.substr(
0,
paddedLength - String( number ).length ) + String( number );
}

我也遇到显示问题的问题更改目录中的斜线ommands。它们刚被淘汰,我不知道如何让它们出现。
I am also having the problem of displaying the slashes in the change
directory commands. they are just eliminated and i am not sure how to
make them appear.



所以,要创建dscf0013.jpg,你可以写:
var photoNumber = 13;
var filename =''dscf''+ padZeros(photoNumber,4)+''.jpg'';

至于消失的反斜杠:这是因为单个反斜杠
(在字符串文字中)用于创建转义字符。例如,

警告(这是在第一行。\这是在第二行。;

会显示一个警告框,两行文字。 ''\ n''在两个句子之间插入一个
新行。要使用文字反斜杠,请将两个
放在一起:

alert(" C:\\ Windows \\Readme.txt");
那会显示,C:\ Windows \ Readme.txt

你的脚本还有其他几个问题(缺少类型检查,
SCRIPT标签中没有类型属性)但是对我来说太晚了(时间紧迫)现在对他们发表评论。别人会接受他们,我很有信心。



So, to create dscf0013.jpg, you could write:

var photoNumber = 13;
var filename = ''dscf'' + padZeros( photoNumber, 4 ) + ''.jpg'';

As for the disappearing backslashes: this is because a single backslash
(in a string literal) is used to create escape characters. For example,

alert( "This is on the first line.\nThis is on the second line." );

would display an alert box that has two lines of text. The ''\n'' inserts a
new line between the two sentences. To use a literal backslash, place two
together:

alert( "C:\\Windows\\Readme.txt" );

That would display, C:\Windows\Readme.txt

There are several other problems with your script (lack of type checking,
no type attribute in the SCRIPT tag) but it''s too late (time-wise) for me
to comment on them now. Someone else will pick up on them, I''m sure.

P.S。对不起,这是解决问题,而不是直截了当的
但我坚信,问题的背景故事会带来更快捷的解决方案。
P.S. sorry this is sol drawn out and not really straight to the point
but i am a firm believer that backstory of the problem brings about a
much swifter solution.


不要。它比以下更好,更优选:这不会起作用。为什么?

希望有所帮助,
Mike



Don''t be. It''s far better, and much more preferable, than: "This doesn''t
work. Why?"

Hope that helps,
Mike



我会试试这些建议,看看会发生什么。我也会发布我的结果
。感谢您的投入,如果有其他人感觉

喜欢以我的方式投掷我的想法,那么请随意。再一次

谢谢你,我会用结果更新这个。


I will give these suggestions a try and see what happens. I will also
post my results. Thank you for the input and if anyone else feels
like throwing mor ideas my way then please feel free. Once again
thank you and I will update this with results.


这篇关于Javascript和额外的零。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆